From a3044769c044136ba7ae834f361231393500bc3b Mon Sep 17 00:00:00 2001 From: Angel Moya - PESOL Date: Thu, 30 Mar 2017 20:06:15 +0200 Subject: [PATCH 1/2] account_invoice_tax_required (#404) --- account_invoice_tax_required/README.rst | 40 +++++++--- account_invoice_tax_required/__init__.py | 22 +----- account_invoice_tax_required/__manifest__.py | 27 ++----- .../models/__init__.py | 22 +----- .../models/account_invoice.py | 43 ++++------- .../tests/__init__.py | 6 ++ .../test_account_invoice_tax_required.py | 73 +++++++++++++++++++ 7 files changed, 139 insertions(+), 94 deletions(-) create mode 100644 account_invoice_tax_required/tests/__init__.py create mode 100644 account_invoice_tax_required/tests/test_account_invoice_tax_required.py diff --git a/account_invoice_tax_required/README.rst b/account_invoice_tax_required/README.rst index 9ef588456..4e1aaa948 100644 --- a/account_invoice_tax_required/README.rst +++ b/account_invoice_tax_required/README.rst @@ -1,19 +1,37 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================================================== Account invoice with tax required in invoice line ================================================== This module adds functional a check on invoice to force user to set tax on invoice line. +Usage +===== + +To use this module, you need to: + +#. Go to Accounting (or Invoicing) > Sales > Customer Invoices. +#. Create a new invoice. +#. Insert a new invoice line without taxes. +#. Press on "Validate". +#. An error will raise preventing to do it. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/92/9.0 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 smashing it by providing a detailed and welcomed feedback -`here `_. - +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 smashing it by providing a detailed and welcomed feedback. Credits ======= @@ -22,17 +40,19 @@ Contributors ------------ * Vincent Renaville +* Angel Moya Maintainer ---------- -.. image:: http://odoo-community.org/logo.png +.. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association - :target: http://odoo-community.org + :target: https://odoo-community.org This module is maintained by the OCA. -OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. - -To contribute to this module, please visit http://odoo-community.org. +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. +To contribute to this module, please visit https://odoo-community.org. diff --git a/account_invoice_tax_required/__init__.py b/account_invoice_tax_required/__init__.py index ebb9d9601..ac63e99a2 100644 --- a/account_invoice_tax_required/__init__.py +++ b/account_invoice_tax_required/__init__.py @@ -1,20 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author Vincent Renaville. Copyright 2015 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# Copyright 2015 - Camptocamp SA - Author Vincent Renaville +# Copyright 2016 - Tecnativa - Angel Moya +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from . import models diff --git a/account_invoice_tax_required/__manifest__.py b/account_invoice_tax_required/__manifest__.py index b1ca7a782..f006e5040 100644 --- a/account_invoice_tax_required/__manifest__.py +++ b/account_invoice_tax_required/__manifest__.py @@ -1,31 +1,16 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author Vincent Renaville. Copyright 2015 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# Copyright 2015 - Camptocamp SA - Author Vincent Renaville +# Copyright 2016 - Tecnativa - Angel Moya +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': "Tax required in invoice", - 'version': "8.0.1.0.0", - "author": "Camptocamp,Odoo Community Association (OCA)", + 'version': "9.0.1.0.0", + "author": "Camptocamp,Tecnativa,Odoo Community Association (OCA)", 'website': "http://www.camptocamp.com", 'category': "Localisation / Accounting", 'license': "AGPL-3", 'depends': ["account"], 'data': [ ], - 'installable': False, + 'installable': True, } diff --git a/account_invoice_tax_required/models/__init__.py b/account_invoice_tax_required/models/__init__.py index ea7bac2d5..77c71a191 100644 --- a/account_invoice_tax_required/models/__init__.py +++ b/account_invoice_tax_required/models/__init__.py @@ -1,20 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author Vincent Renaville. Copyright 2015 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# Copyright 2015 - Camptocamp SA - Author Vincent Renaville +# Copyright 2016 - Tecnativa - Angel Moya +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from . import account_invoice diff --git a/account_invoice_tax_required/models/account_invoice.py b/account_invoice_tax_required/models/account_invoice.py index 836ef236c..b1cc8ba55 100644 --- a/account_invoice_tax_required/models/account_invoice.py +++ b/account_invoice_tax_required/models/account_invoice.py @@ -1,23 +1,10 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author Vincent Renaville. Copyright 2015 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# Copyright 2015 - Camptocamp SA - Author Vincent Renaville +# Copyright 2016 - Tecnativa - Angel Moya +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from openerp import models, api, exceptions, _ +from openerp.tools import config class AccountInvoice(models.Model): @@ -27,20 +14,22 @@ class AccountInvoice(models.Model): def test_invoice_line_tax(self): errors = [] error_template = _("Invoice has a line with product %s with no taxes") - for invoice in self: - for invoice_line in invoice.invoice_line: - if not invoice_line.invoice_line_tax_id: - error_string = error_template % (invoice_line.name) - errors.append(error_string) + for invoice_line in self.mapped('invoice_line_ids'): + if not invoice_line.invoice_line_tax_ids: + error_string = error_template % (invoice_line.name) + errors.append(error_string) if errors: - errors_full_string = ','.join(x for x in errors) - raise exceptions.Warning(_('No Taxes Defined!'), - errors_full_string) + raise exceptions.Warning( + _('%s\n%s') % (_('No Taxes Defined!'), + '\n'.join(x for x in errors)) + ) else: return True @api.multi def invoice_validate(self): - self.test_invoice_line_tax() + if not (config['test_enable'] and + not self.env.context.get('test_tax_required')): + self.test_invoice_line_tax() res = super(AccountInvoice, self).invoice_validate() return res diff --git a/account_invoice_tax_required/tests/__init__.py b/account_invoice_tax_required/tests/__init__.py new file mode 100644 index 000000000..ce23ac4c9 --- /dev/null +++ b/account_invoice_tax_required/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 - Camptocamp SA - Author Vincent Renaville +# Copyright 2016 - Tecnativa - Angel Moya +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_account_invoice_tax_required diff --git a/account_invoice_tax_required/tests/test_account_invoice_tax_required.py b/account_invoice_tax_required/tests/test_account_invoice_tax_required.py new file mode 100644 index 000000000..7c4eb848d --- /dev/null +++ b/account_invoice_tax_required/tests/test_account_invoice_tax_required.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 - Tecnativa - Angel Moya +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.tests.common import TransactionCase +from openerp import exceptions + + +class TestAccountInvoiceTaxRequired(TransactionCase): + + def setUp(self): + super(TestAccountInvoiceTaxRequired, self).setUp() + + self.account_invoice = self.env['account.invoice'] + self.account_journal = self.env['account.journal'] + self.journal = self.account_journal.create({ + 'code': 'test', + 'name': 'test', + 'type': 'sale' + }) + self.partner = self.env.ref('base.res_partner_3') + account_user_type = self.env.ref( + 'account.data_account_type_receivable') + + self.account_account = self.env['account.account'] + self.account_rec1_id = self.account_account.create(dict( + code="cust_acc", + name="customer account", + user_type_id=account_user_type.id, + reconcile=True, + )) + self.product_product = self.env['product.product'] + self.product = self.product_product.create({ + 'name': 'Test', + 'categ_id': self.env.ref( + "product.product_category_all").id, + 'standard_price': 50, + 'list_price': 100, + 'type': 'service', + 'uom_id': self.env.ref("product.product_uom_unit").id, + 'uom_po_id': self.env.ref("product.product_uom_unit").id, + 'description': 'Test', + }) + + invoice_line_data = [(0, 0, { + 'product_id': self.product.id, + 'quantity': 10.0, + 'account_id': self.account_account.search( + [('user_type_id', + '=', + self.env.ref('account.data_account_type_revenue').id) + ], limit=1).id, + 'name': 'product test 5', + 'price_unit': 100.00, + })] + + self.invoice = self.account_invoice.create(dict( + name="Test Customer Invoice", + reference_type="none", + journal_id=self.journal.id, + partner_id=self.partner.id, + account_id=self.account_rec1_id.id, + invoice_line_ids=invoice_line_data + )) + + def test_exception(self): + """Validate invoice without tax must raise exception + """ + self.invoice.action_date_assign() + self.invoice.action_move_create() + with self.assertRaises(exceptions.Warning): + self.invoice.with_context( + test_tax_required=True).invoice_validate() From e0adcc81b717bab8611233c403ac7a0697a8965e Mon Sep 17 00:00:00 2001 From: Kitti U Date: Tue, 16 May 2017 23:22:39 +0700 Subject: [PATCH 2/2] [MIG] account_tax_invoice_required: Migrated to 10.0 --- account_invoice_tax_required/README.rst | 3 ++- account_invoice_tax_required/__manifest__.py | 2 +- .../models/account_invoice.py | 13 ++++++------- .../tests/test_account_invoice_tax_required.py | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/account_invoice_tax_required/README.rst b/account_invoice_tax_required/README.rst index 4e1aaa948..8fd6a3bb4 100644 --- a/account_invoice_tax_required/README.rst +++ b/account_invoice_tax_required/README.rst @@ -22,7 +22,7 @@ To use this module, you need to: .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/92/9.0 + :target: https://runbot.odoo-community.org/runbot/92/10.0 Bug Tracker @@ -41,6 +41,7 @@ Contributors * Vincent Renaville * Angel Moya +* Kitti U. Maintainer ---------- diff --git a/account_invoice_tax_required/__manifest__.py b/account_invoice_tax_required/__manifest__.py index f006e5040..ef0df1f99 100644 --- a/account_invoice_tax_required/__manifest__.py +++ b/account_invoice_tax_required/__manifest__.py @@ -4,7 +4,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': "Tax required in invoice", - 'version': "9.0.1.0.0", + 'version': "10.0.1.0.0", "author": "Camptocamp,Tecnativa,Odoo Community Association (OCA)", 'website': "http://www.camptocamp.com", 'category': "Localisation / Accounting", diff --git a/account_invoice_tax_required/models/account_invoice.py b/account_invoice_tax_required/models/account_invoice.py index b1cc8ba55..e3101fb3c 100644 --- a/account_invoice_tax_required/models/account_invoice.py +++ b/account_invoice_tax_required/models/account_invoice.py @@ -3,15 +3,16 @@ # Copyright 2016 - Tecnativa - Angel Moya # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import models, api, exceptions, _ -from openerp.tools import config +from odoo import models, api, _ +from odoo.exceptions import UserError +from odoo.tools import config class AccountInvoice(models.Model): _inherit = "account.invoice" @api.multi - def test_invoice_line_tax(self): + def _test_invoice_line_tax(self): errors = [] error_template = _("Invoice has a line with product %s with no taxes") for invoice_line in self.mapped('invoice_line_ids'): @@ -19,17 +20,15 @@ class AccountInvoice(models.Model): error_string = error_template % (invoice_line.name) errors.append(error_string) if errors: - raise exceptions.Warning( + raise UserError( _('%s\n%s') % (_('No Taxes Defined!'), '\n'.join(x for x in errors)) ) - else: - return True @api.multi def invoice_validate(self): if not (config['test_enable'] and not self.env.context.get('test_tax_required')): - self.test_invoice_line_tax() + self._test_invoice_line_tax() res = super(AccountInvoice, self).invoice_validate() return res diff --git a/account_invoice_tax_required/tests/test_account_invoice_tax_required.py b/account_invoice_tax_required/tests/test_account_invoice_tax_required.py index 7c4eb848d..2c4d5f7ed 100644 --- a/account_invoice_tax_required/tests/test_account_invoice_tax_required.py +++ b/account_invoice_tax_required/tests/test_account_invoice_tax_required.py @@ -2,8 +2,8 @@ # Copyright 2016 - Tecnativa - Angel Moya # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp.tests.common import TransactionCase -from openerp import exceptions +from odoo.tests.common import TransactionCase +from odoo import exceptions class TestAccountInvoiceTaxRequired(TransactionCase):