Merge pull request #484 from kittiu/10.0-mig-account_invoice_tax_required

10.0 mig account invoice tax required
This commit is contained in:
Stéphane Bidoul (ACSONE)
2017-05-30 09:28:55 +02:00
committed by GitHub
7 changed files with 143 additions and 98 deletions

View File

@@ -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 <https://github.com/OCA/account-financial-tools/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 <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_invoice_tax_required%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/account-financial-tools/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 <vincent.renaville@camptocamp.com>
* Angel Moya <odoo@tecnativa.com>
* Kitti U. <kittiu@ecosoft.co.th>
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.

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright 2015 - Camptocamp SA - Author Vincent Renaville
# Copyright 2016 - Tecnativa - Angel Moya <odoo@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright 2015 - Camptocamp SA - Author Vincent Renaville
# Copyright 2016 - Tecnativa - Angel Moya <odoo@tecnativa.com>
# 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,
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright 2015 - Camptocamp SA - Author Vincent Renaville
# Copyright 2016 - Tecnativa - Angel Moya <odoo@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import account_invoice

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, api, exceptions, _
# Copyright 2015 - Camptocamp SA - Author Vincent Renaville
# Copyright 2016 - Tecnativa - Angel Moya <odoo@tecnativa.com>
# 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

View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2015 - Camptocamp SA - Author Vincent Renaville
# Copyright 2016 - Tecnativa - Angel Moya <odoo@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_account_invoice_tax_required

View File

@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
# Copyright 2016 - Tecnativa - Angel Moya <odoo@tecnativa.com>
# 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()