From 5b620a6c5fd432304eac16f1947558dcbe4758f3 Mon Sep 17 00:00:00 2001 From: Iryna Vushnevska Date: Mon, 12 Aug 2019 23:23:00 +0300 Subject: [PATCH] [12.0][MIG] account_invoice_update_wizard --- account_invoice_update_wizard/README.rst | 39 +++++++++++++++ account_invoice_update_wizard/__manifest__.py | 29 +++-------- .../test_account_invoice_update_wizard.py | 50 +++++++++---------- .../views/account_invoice.xml | 6 +-- .../wizard/account_invoice_update.py | 13 +++-- 5 files changed, 80 insertions(+), 57 deletions(-) create mode 100644 account_invoice_update_wizard/README.rst diff --git a/account_invoice_update_wizard/README.rst b/account_invoice_update_wizard/README.rst new file mode 100644 index 0000000..c835502 --- /dev/null +++ b/account_invoice_update_wizard/README.rst @@ -0,0 +1,39 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: https://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +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: + +* 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) +* Bank Account +* Salesman +* Notes +* Description of invoice lines +* Analytic account +* Analytic tags + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Contributors +------------ + +* Alexis de Lattre +* Florian da Costa +* Matthieu Dietrich +* Yannick Vaucher +* Mykhailo Panarin +* Artem Kostyuk diff --git a/account_invoice_update_wizard/__manifest__.py b/account_invoice_update_wizard/__manifest__.py index eced67e..10b3e37 100644 --- a/account_invoice_update_wizard/__manifest__.py +++ b/account_invoice_update_wizard/__manifest__.py @@ -1,34 +1,19 @@ # -*- coding: utf-8 -*- -# © 2017 Akretion (Alexis de Lattre ) -# Copyright 2018 Camptocamp +# Copyright 2017 Akretion (Alexis de Lattre ) +# Copyright 2019 Camptocamp # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Account Invoice Update Wizard', - 'version': '8.0.1.0.0', + 'version': '12.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: - -* 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) -* Bank Account -* Salesman -* Notes -* Description of invoice lines -* Analytic account -* Analytic tags - - """, 'author': 'Akretion', - 'website': 'http://www.akretion.com', - 'depends': ['account'], + 'website': 'https://github.com/akretion/odoo-usability', + 'depends': [ + 'account' + ], 'data': [ 'wizard/account_invoice_update_view.xml', 'views/account_invoice.xml', diff --git a/account_invoice_update_wizard/tests/test_account_invoice_update_wizard.py b/account_invoice_update_wizard/tests/test_account_invoice_update_wizard.py index 737f266..a6ab2e2 100644 --- a/account_invoice_update_wizard/tests/test_account_invoice_update_wizard.py +++ b/account_invoice_update_wizard/tests/test_account_invoice_update_wizard.py @@ -1,46 +1,46 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 Camptocamp +# Copyright 2019 Camptocamp # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.tests.common import TransactionCase +from odoo.tests.common import SavepointCase from odoo.exceptions import UserError -class TestAccountInvoiceUpdateWizard(TransactionCase): +class TestAccountInvoiceUpdateWizard(SavepointCase): - def setUp(self): - 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') + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.customer12 = cls.env.ref('base.res_partner_12') + cls.product16 = cls.env.ref('product.product_product_16') + cls.product24 = cls.env.ref('product.product_product_24') + uom_unit = cls.env.ref('uom.product_uom_categ_unit') - self.invoice1 = self.env['account.invoice'].create({ + cls.invoice1 = cls.env['account.invoice'].create({ 'name': 'Test invoice', - 'partner_id': self.customer12.id, + 'partner_id': cls.customer12.id, }) - self.inv_line1 = self.env['account.invoice.line'].create({ - 'invoice_id': self.invoice1.id, + cls.inv_line1 = cls.env['account.invoice.line'].create({ + 'invoice_id': cls.invoice1.id, 'name': "Line1", - 'product_id': self.product16.id, + 'product_id': cls.product16.id, 'product_uom_id': uom_unit.id, - 'account_id': self.invoice1.account_id.id, + 'account_id': cls.invoice1.account_id.id, 'price_unit': 42.0, }) - self.inv_line2 = self.env['account.invoice.line'].create({ - 'invoice_id': self.invoice1.id, + cls.inv_line2 = cls.env['account.invoice.line'].create({ + 'invoice_id': cls.invoice1.id, 'name': "Line2", - 'product_id': self.product24.id, + 'product_id': cls.product24.id, 'product_uom_id': uom_unit.id, - 'account_id': self.invoice1.account_id.id, + 'account_id': cls.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': u'の', + cls.aa1 = cls.env.ref('analytic.analytic_partners_camp_to_camp') + cls.aa2 = cls.env.ref('analytic.analytic_nebula') + cls.atag1 = cls.env.ref('analytic.tag_contract') + cls.atag2 = cls.env['account.analytic.tag'].create({ + 'name': 'の', }) def create_wizard(self): diff --git a/account_invoice_update_wizard/views/account_invoice.xml b/account_invoice_update_wizard/views/account_invoice.xml index 312f7d7..f4737b5 100644 --- a/account_invoice_update_wizard/views/account_invoice.xml +++ b/account_invoice_update_wizard/views/account_invoice.xml @@ -1,6 +1,6 @@ @@ -10,7 +10,7 @@ account.invoice - @@ -20,7 +20,7 @@ account.invoice - diff --git a/account_invoice_update_wizard/wizard/account_invoice_update.py b/account_invoice_update_wizard/wizard/account_invoice_update.py index 6e0022b..755bf33 100644 --- a/account_invoice_update_wizard/wizard/account_invoice_update.py +++ b/account_invoice_update_wizard/wizard/account_invoice_update.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- -# © 2017 Akretion (Alexis de Lattre ) -# Copyright 2018 Camptocamp +# Copyright 2017 Akretion (Alexis de Lattre ) +# Copyright 2019 Camptocamp # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, fields, api, _ @@ -58,7 +57,7 @@ class AccountInvoiceUpdate(models.TransientModel): 'price_subtotal': line.price_subtotal, 'account_analytic_id': line.account_analytic_id.id, 'analytic_tag_ids': aa_tags, - }]) + }]) return res @api.model @@ -141,7 +140,7 @@ class AccountInvoiceUpdate(models.TransientModel): # be grouped unless journal.group_invoice_line is True inv_line = self.invoice_id.invoice_line_ids.filtered( lambda rec: rec.product_id == move_line.product_id) - if len(inv_line) <> 1: + if len(inv_line) != 1: raise UserError( "Cannot match a single invoice line to move line %s" % move_line.name) @@ -221,7 +220,7 @@ class AccountInvoiceUpdate(models.TransientModel): mlines[amount].append(line) else: mlines[amount] = [line] - for iamount, lines in mlines.iteritems(): + for iamount, lines in mlines.items(): if len(lines) != len(new_pterm.get(iamount, [])): raise UserError(_( "The original payment term '%s' doesn't have the " @@ -282,7 +281,7 @@ class AccountInvoiceUpdate(models.TransientModel): updated = True line.invoice_line_id.write(ilvals) if updated: - inv.message_post(_( + inv.message_post(body=_( 'Non-legal fields of invoice updated via the Invoice Update ' 'wizard.')) return True