Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.0][MIG] account_invoice_update_wizard #75

Open
wants to merge 9 commits into
base: 11.0
Choose a base branch
from
1 change: 1 addition & 0 deletions account_invoice_update_wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import wizard
37 changes: 37 additions & 0 deletions account_invoice_update_wizard/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2017 Akretion (Alexis de Lattre <[email protected]>)
# Copyright 2018 Camptocamp
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'Account Invoice Update Wizard',
'version': '11.0.1.0.0',
'category': 'Accounting & Finance',
'license': 'AGPL-3',
'summary': 'Wizard to update non-legal fields of an open/paid invoice',
'description': """
Account Invoice Update Wizard
=============================

This module adds a button *Update Invoice* on Customer and Supplier invoices in Open or Paid state. This button starts a wizard which allows the user to update non-legal fields of the invoice:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move 'This button starts...' to a new line


* Source Document
* Reference/Description
* Payment terms (update allowed only to a payment term with same number of terms of the same amount and on invoices without any payment)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same: make this more readable... new lines are cheap ;)

* Bank Account
* Salesman
* Notes
* Description of invoice lines
* Analytic account
* Analytic tags

""",
'author': 'Akretion',
'website': 'http://www.akretion.com',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is published on odoo apps it would be better to have https://github.com/akretion/odoo-usability

'depends': [
'account',
],
'data': [
'wizard/account_invoice_update_view.xml',
'views/account_invoice.xml',
],
}
1 change: 1 addition & 0 deletions account_invoice_update_wizard/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_account_invoice_update_wizard
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# Copyright 2018 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError


class TestAccountInvoiceUpdateWizard(TransactionCase):

def setUp(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use SavepointCase + setUpClass + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))

super(TestAccountInvoiceUpdateWizard, self).setUp()
self.customer12 = self.env.ref('base.res_partner_12')
self.product16 = self.env.ref('product.product_product_16')
self.product24 = self.env.ref('product.product_product_24')
uom_unit = self.env.ref('product.product_uom_categ_unit')

self.invoice1 = self.env['account.invoice'].create({
'name': 'Test invoice',
'partner_id': self.customer12.id,
})
self.inv_line1 = self.env['account.invoice.line'].create({
'invoice_id': self.invoice1.id,
'name': "Line1",
'product_id': self.product16.id,
'product_uom_id': uom_unit.id,
'account_id': self.invoice1.account_id.id,
'price_unit': 42.0,
})
self.inv_line2 = self.env['account.invoice.line'].create({
'invoice_id': self.invoice1.id,
'name': "Line2",
'product_id': self.product24.id,
'product_uom_id': uom_unit.id,
'account_id': self.invoice1.account_id.id,
'price_unit': 1111.1,
})

self.aa1 = self.env.ref('analytic.analytic_partners_camp_to_camp')
self.aa2 = self.env.ref('analytic.analytic_nebula')
self.atag1 = self.env.ref('analytic.tag_contract')
self.atag2 = self.env['account.analytic.tag'].create({
'name': 'の',
})

def create_wizard(self):
UpdateWizard = self.env['account.invoice.update'].with_context(
active_model='account.invoice',
active_id=self.invoice1.id)
self.wiz = UpdateWizard.create({})

def test_add_analytic_account_line1(self):
""" Add analytic account on an invoice line
after the invoice has been approved.

This will:
- update the move line
- create a new analytic line.
"""
self.invoice1.action_invoice_open()
self.create_wizard()

wiz_line = self.wiz.line_ids.filtered(
lambda rec: rec.invoice_line_id == self.inv_line1)
wiz_line.account_analytic_id = self.aa1
self.wiz.run()

related_ml = self.invoice1.move_id.line_ids.filtered(
lambda rec: rec.product_id == self.product16)
self.assertEqual(related_ml.analytic_account_id, self.aa1)
self.assertEqual(related_ml.analytic_line_ids.account_id, self.aa1)

def test_change_analytic_account_line1(self):
""" Change analytic account on an invoice line
after the invoice has been approved.

This will:
- update the move line
- update the existing analytic line."""
self.inv_line1.account_analytic_id = self.aa2

self.invoice1.action_invoice_open()
self.create_wizard()

wiz_line = self.wiz.line_ids.filtered(
lambda rec: rec.invoice_line_id == self.inv_line1)
wiz_line.account_analytic_id = self.aa1
self.wiz.run()

related_ml = self.invoice1.move_id.line_ids.filtered(
lambda rec: rec.product_id == self.product16)
self.assertEqual(related_ml.analytic_account_id, self.aa1)
self.assertEqual(related_ml.analytic_line_ids.account_id, self.aa1)

def test_error_grouped_move_lines(self):
""" Change analytic account on an invoice line
after the invoice has been approved where both
lines were grouped in the same move line.

This will raise an error.
"""
self.invoice1.journal_id.group_invoice_lines = True

self.inv_line2.product_id = self.product16
self.inv_line2.unit_price = 42.0

self.invoice1.action_invoice_open()
self.create_wizard()

line1 = self.wiz.line_ids[0]
line1.account_analytic_id = self.aa1
with self.assertRaises(UserError):
self.wiz.run()

def test_add_analytic_tags_line1(self):
""" Add analytic tags on an invoice line
after the invoice has been approved.

This will update move line.
"""
self.invoice1.action_invoice_open()
self.create_wizard()

wiz_line = self.wiz.line_ids.filtered(
lambda rec: rec.invoice_line_id == self.inv_line1)
wiz_line.analytic_tag_ids = self.atag2
self.wiz.run()

related_ml = self.invoice1.move_id.line_ids.filtered(
lambda rec: rec.product_id == self.product16)
self.assertEqual(related_ml.analytic_tag_ids, self.atag2)
self.assertFalse(related_ml.analytic_line_ids)

def test_change_analytic_tags_line1(self):
""" Change analytic tags on an invoice line
after the invoice has been approved.

It will update move line and analytic line
"""
self.inv_line1.account_analytic_id = self.aa2
self.inv_line1.analytic_tag_ids = self.atag1

self.invoice1.action_invoice_open()
self.create_wizard()

wiz_line = self.wiz.line_ids.filtered(
lambda rec: rec.invoice_line_id == self.inv_line1)
wiz_line.analytic_tag_ids = self.atag2
self.wiz.run()

related_ml = self.invoice1.move_id.line_ids.filtered(
lambda rec: rec.product_id == self.product16)
self.assertEqual(related_ml.analytic_tag_ids, self.atag2)
self.assertEqual(related_ml.analytic_line_ids.tag_ids, self.atag2)

def test_add_analytic_info_line1(self):
""" Add analytic account and tags on an invoice line
after the invoice has been approved.

This will:
- update move line
- create an analytic line
"""
self.invoice1.action_invoice_open()
self.create_wizard()

wiz_line = self.wiz.line_ids.filtered(
lambda rec: rec.invoice_line_id == self.inv_line1)
wiz_line.account_analytic_id = self.aa1
wiz_line.analytic_tag_ids = self.atag2
self.wiz.run()

related_ml = self.invoice1.move_id.line_ids.filtered(
lambda rec: rec.product_id == self.product16)
self.assertEqual(related_ml.analytic_account_id, self.aa1)
self.assertEqual(related_ml.analytic_tag_ids, self.atag2)
self.assertEqual(related_ml.analytic_line_ids.account_id, self.aa1)
self.assertEqual(related_ml.analytic_line_ids.tag_ids, self.atag2)

def test_empty_analytic_account_line1(self):
""" Remove analytic account
after the invoice has been approved.

This will raise an error as it is not implemented.
"""
self.inv_line1.account_analytic_id = self.aa2

self.invoice1.action_invoice_open()
self.create_wizard()

wiz_line = self.wiz.line_ids.filtered(
lambda rec: rec.invoice_line_id == self.inv_line1)
wiz_line.account_analytic_id = False
self.wiz.run()
related_ml = self.invoice1.move_id.line_ids.filtered(
lambda rec: rec.product_id == self.product16)
self.assertFalse(related_ml.analytic_account_id)
self.assertFalse(related_ml.analytic_line_ids)
29 changes: 29 additions & 0 deletions account_invoice_update_wizard/views/account_invoice.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2017 Akretion (Alexis de Lattre <[email protected]>)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright

License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->

<odoo>

<record id="invoice_supplier_form" model="ir.ui.view">
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="arch" type="xml">
<button name="action_invoice_cancel" position="before">
<button name="%(account_invoice_update_action)d" type="action" string="Update Invoice" states="open,paid" groups="account.group_account_invoice"/>
</button>
</field>
</record>

<record id="invoice_form" model="ir.ui.view">
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<button name="action_invoice_cancel" position="before">
<button name="%(account_invoice_update_action)d" type="action" string="Update Invoice" states="open,paid" groups="account.group_account_invoice"/>
</button>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions account_invoice_update_wizard/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_invoice_update
Loading