diff --git a/account_invoice_tax_required/README.rst b/account_invoice_tax_required/README.rst index 9ef588456..8fd6a3bb4 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/10.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,20 @@ Contributors ------------ * Vincent Renaville +* Angel Moya +* Kitti U. 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..ef0df1f99 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': "10.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..e3101fb3c 100644 --- a/account_invoice_tax_required/models/account_invoice.py +++ b/account_invoice_tax_required/models/account_invoice.py @@ -1,46 +1,34 @@ # -*- 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 . -# -############################################################################## -from openerp import models, api, exceptions, _ +# 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 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 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) - else: - return True + raise UserError( + _('%s\n%s') % (_('No Taxes Defined!'), + '\n'.join(x for x in errors)) + ) @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..2c4d5f7ed --- /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 odoo.tests.common import TransactionCase +from odoo 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()