From 3c687c97374826c0fd02d9fb7a8d9cd71345a726 Mon Sep 17 00:00:00 2001 From: eLBati Date: Thu, 16 Aug 2018 14:40:30 +0200 Subject: [PATCH] ADD l10n_it_vat_registries_split_payment to fix the following case: - Configure Split Payment fiscal position and tax - Make a customer invoice with SP - Print VAT register Split Payment VAT must not appear as deductible VAT --- l10n_it_split_payment/__manifest__.py | 6 +- l10n_it_split_payment/models/__init__.py | 1 + l10n_it_split_payment/models/account_tax.py | 19 ++++ .../tests/test_splitpayment.py | 17 ++- .../README.rst | 69 ++++++++++++ .../__init__.py | 4 + .../__manifest__.py | 21 ++++ .../models/__init__.py | 4 + .../models/account_tax.py | 16 +++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + .../tests/__init__.py | 3 + .../tests/test_sp.py | 101 ++++++++++++++++++ 13 files changed, 256 insertions(+), 7 deletions(-) create mode 100644 l10n_it_split_payment/models/account_tax.py create mode 100644 l10n_it_vat_registries_split_payment/README.rst create mode 100644 l10n_it_vat_registries_split_payment/__init__.py create mode 100644 l10n_it_vat_registries_split_payment/__manifest__.py create mode 100644 l10n_it_vat_registries_split_payment/models/__init__.py create mode 100644 l10n_it_vat_registries_split_payment/models/account_tax.py create mode 100644 l10n_it_vat_registries_split_payment/readme/CONTRIBUTORS.rst create mode 100644 l10n_it_vat_registries_split_payment/readme/DESCRIPTION.rst create mode 100644 l10n_it_vat_registries_split_payment/tests/__init__.py create mode 100644 l10n_it_vat_registries_split_payment/tests/test_sp.py diff --git a/l10n_it_split_payment/__manifest__.py b/l10n_it_split_payment/__manifest__.py index dfe06ab2618b..312800fc8201 100644 --- a/l10n_it_split_payment/__manifest__.py +++ b/l10n_it_split_payment/__manifest__.py @@ -1,17 +1,17 @@ # -*- coding: utf-8 -*- # Copyright 2015 Davide Corio -# Copyright 2015-2016 Lorenzo Battistini - Agile Business Group +# Copyright 2015-2018 Lorenzo Battistini - Agile Business Group # Copyright 2016 Alessio Gerace - Agile Business Group # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Split Payment', - 'version': '10.0.1.0.0', + 'version': '10.0.1.1.0', 'category': 'Localization/Italy', 'summary': 'Split Payment', 'author': 'Abstract, Agile Business Group, ' 'Odoo Community Association (OCA)', - 'website': 'http://www.abstract.it', + 'website': 'https://github.com/OCA/l10n-italy', 'license': 'AGPL-3', 'depends': ['account'], 'data': [ diff --git a/l10n_it_split_payment/models/__init__.py b/l10n_it_split_payment/models/__init__.py index d0a511a269ab..cf631cba086f 100644 --- a/l10n_it_split_payment/models/__init__.py +++ b/l10n_it_split_payment/models/__init__.py @@ -6,3 +6,4 @@ from . import account from . import config +from . import account_tax diff --git a/l10n_it_split_payment/models/account_tax.py b/l10n_it_split_payment/models/account_tax.py new file mode 100644 index 000000000000..145a128cb408 --- /dev/null +++ b/l10n_it_split_payment/models/account_tax.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields, api + + +class AccountTax(models.Model): + _inherit = 'account.tax' + is_split_payment = fields.Boolean( + "Is split payment", compute="_compute_is_split_payment") + + @api.multi + def _compute_is_split_payment(self): + for tax in self: + fp_lines = self.env['account.fiscal.position.tax'].search( + [('tax_dest_id', '=', tax.id)]) + tax.is_split_payment = any( + fp_line.position_id.split_payment for fp_line in fp_lines + ) diff --git a/l10n_it_split_payment/tests/test_splitpayment.py b/l10n_it_split_payment/tests/test_splitpayment.py index 9968692d6935..8405fffcb755 100644 --- a/l10n_it_split_payment/tests/test_splitpayment.py +++ b/l10n_it_split_payment/tests/test_splitpayment.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Copyright 2015 Davide Corio -# Copyright 2015-2016 Lorenzo Battistini - Agile Business Group +# Copyright 2015-2018 Lorenzo Battistini - Agile Business Group # Copyright 2016 Alessio Gerace - Agile Business Group # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -16,6 +16,10 @@ def setUp(self): self.term_model = self.env['account.payment.term'] self.inv_line_model = self.env['account.invoice.line'] self.fp_model = self.env['account.fiscal.position'] + self.tax22sp = self.tax_model.create({ + 'name': '22% SP', + 'amount': 22, + }) self.tax22 = self.tax_model.create({ 'name': '22%', 'amount': 22, @@ -23,6 +27,10 @@ def setUp(self): self.sp_fp = self.fp_model.create({ 'name': 'Split payment', 'split_payment': True, + 'tax_ids': [(0, 0, { + 'tax_src_id': self.tax22.id, + 'tax_dest_id': self.tax22sp.id + })] }) self.company = self.env.ref('base.main_company') self.company.sp_account_id = self.env['account.account'].search([ @@ -69,6 +77,7 @@ def setUp(self): limit=1).date_invoice def test_invoice(self): + self.assertTrue(self.tax22sp.is_split_payment) invoice = self.invoice_model.create({ 'date_invoice': self.recent_date, 'partner_id': self.env.ref('base.res_partner_3').id, @@ -81,7 +90,7 @@ def test_invoice(self): 'quantity': 1, 'price_unit': 100, 'invoice_line_tax_ids': [(6, 0, { - self.tax22.id + self.tax22sp.id })] })] }) @@ -116,7 +125,7 @@ def test_invoice(self): 'quantity': 1, 'price_unit': 100, 'invoice_line_tax_ids': [(6, 0, { - self.tax22.id + self.tax22sp.id })] })] }) @@ -151,7 +160,7 @@ def test_invoice(self): 'quantity': 1, 'price_unit': 100, 'invoice_line_tax_ids': [(6, 0, { - self.tax22.id + self.tax22sp.id })] })] }) diff --git a/l10n_it_vat_registries_split_payment/README.rst b/l10n_it_vat_registries_split_payment/README.rst new file mode 100644 index 000000000000..cb6b8d7fa7f4 --- /dev/null +++ b/l10n_it_vat_registries_split_payment/README.rst @@ -0,0 +1,69 @@ +============================== +VAT registries + Split Payment +============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github + :target: https://github.com/OCA/l10n-italy/tree/10.0/l10n_it_vat_registries_split_payment + :alt: OCA/l10n-italy +.. |badge4| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/122/10.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| + +Bridge module to make VAT registries module work along with Split Payment module + +**Table of contents** + +.. contents:: + :local: + +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. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Agile Business Group + +Contributors +~~~~~~~~~~~~ + +* Lorenzo Battistini + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://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. + +This module is part of the `OCA/l10n-italy `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/l10n_it_vat_registries_split_payment/__init__.py b/l10n_it_vat_registries_split_payment/__init__.py new file mode 100644 index 000000000000..b44d765940f6 --- /dev/null +++ b/l10n_it_vat_registries_split_payment/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/l10n_it_vat_registries_split_payment/__manifest__.py b/l10n_it_vat_registries_split_payment/__manifest__.py new file mode 100644 index 000000000000..bac0d8543d81 --- /dev/null +++ b/l10n_it_vat_registries_split_payment/__manifest__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Lorenzo Battistini +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "VAT registries + Split Payment", + "summary": "Bridge module to make VAT registries work with Split Payment", + "version": "10.0.1.0.0", + "development_status": "Beta", + "category": "Hidden", + "website": "https://github.com/OCA/l10n-italy/", + "author": "Agile Business Group, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "depends": [ + "l10n_it_vat_registries", + "l10n_it_split_payment" + ], +} diff --git a/l10n_it_vat_registries_split_payment/models/__init__.py b/l10n_it_vat_registries_split_payment/models/__init__.py new file mode 100644 index 000000000000..43583b2f71f7 --- /dev/null +++ b/l10n_it_vat_registries_split_payment/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import account_tax diff --git a/l10n_it_vat_registries_split_payment/models/account_tax.py b/l10n_it_vat_registries_split_payment/models/account_tax.py new file mode 100644 index 000000000000..ae8b78708b87 --- /dev/null +++ b/l10n_it_vat_registries_split_payment/models/account_tax.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountTax(models.Model): + _inherit = 'account.tax' + + def _compute_totals_tax(self, data): + res = super(AccountTax, self)._compute_totals_tax(data) + if self.is_split_payment: + # res is (tax_name, base, tax, deductible, undeductible) + # so, in case of SP, SP VAT must not appear as deductible + return (res[0], res[1], res[2], 0.0, res[4]) + return res diff --git a/l10n_it_vat_registries_split_payment/readme/CONTRIBUTORS.rst b/l10n_it_vat_registries_split_payment/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..65a7e30bc6a5 --- /dev/null +++ b/l10n_it_vat_registries_split_payment/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Lorenzo Battistini diff --git a/l10n_it_vat_registries_split_payment/readme/DESCRIPTION.rst b/l10n_it_vat_registries_split_payment/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..2dac6dacef55 --- /dev/null +++ b/l10n_it_vat_registries_split_payment/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Bridge module to make VAT registries module work along with Split Payment module diff --git a/l10n_it_vat_registries_split_payment/tests/__init__.py b/l10n_it_vat_registries_split_payment/tests/__init__.py new file mode 100644 index 000000000000..167c7245e866 --- /dev/null +++ b/l10n_it_vat_registries_split_payment/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import test_sp diff --git a/l10n_it_vat_registries_split_payment/tests/test_sp.py b/l10n_it_vat_registries_split_payment/tests/test_sp.py new file mode 100644 index 000000000000..84ce7e9b76b6 --- /dev/null +++ b/l10n_it_vat_registries_split_payment/tests/test_sp.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- + +from odoo.addons.account.tests.account_test_users import AccountTestUsers + + +class TestSP(AccountTestUsers): + + def setUp(self): + super(TestSP, self).setUp() + self.tax_model = self.env['account.tax'] + self.invoice_model = self.env['account.invoice'] + self.inv_line_model = self.env['account.invoice.line'] + self.fp_model = self.env['account.fiscal.position'] + self.tax22sp = self.tax_model.create({ + 'name': '22% SP', + 'amount': 22, + }) + self.tax22 = self.tax_model.create({ + 'name': '22%', + 'amount': 22, + }) + self.sp_fp = self.fp_model.create({ + 'name': 'Split payment', + 'split_payment': True, + 'tax_ids': [(0, 0, { + 'tax_src_id': self.tax22.id, + 'tax_dest_id': self.tax22sp.id + })] + }) + self.company = self.env.ref('base.main_company') + self.company.sp_account_id = self.env['account.account'].search([ + ( + 'user_type_id', '=', + self.env.ref('account.data_account_type_current_assets').id + ) + ], limit=1) + account_user_type = self.env.ref( + 'account.data_account_type_receivable') + self.a_recv = self.account_model.sudo(self.account_manager.id).create( + dict( + code="cust_acc", + name="customer account", + user_type_id=account_user_type.id, + reconcile=True, + )) + self.a_sale = self.env['account.account'].search([ + ( + 'user_type_id', '=', + self.env.ref('account.data_account_type_revenue').id) + ], limit=1) + self.sales_journal = self.env['account.journal'].search( + [('type', '=', 'sale')])[0] + # Set invoice date to recent date in the system + # This solves problems with account_invoice_sequential_dates + self.recent_date = self.invoice_model.search( + [('date_invoice', '!=', False)], order='date_invoice desc', + limit=1).date_invoice + + def test_invoice(self): + invoice = self.invoice_model.create({ + 'date_invoice': self.recent_date, + 'partner_id': self.env.ref('base.res_partner_3').id, + 'journal_id': self.sales_journal.id, + 'account_id': self.a_recv.id, + 'fiscal_position_id': self.sp_fp.id, + 'invoice_line_ids': [(0, 0, { + 'name': 'service', + 'account_id': self.a_sale.id, + 'quantity': 1, + 'price_unit': 100, + 'invoice_line_tax_ids': [(6, 0, { + self.tax22sp.id + })] + })] + }) + invoice.action_invoice_open() + invoice2 = self.invoice_model.create({ + 'date_invoice': self.recent_date, + 'partner_id': self.env.ref('base.res_partner_3').id, + 'journal_id': self.sales_journal.id, + 'account_id': self.a_recv.id, + 'fiscal_position_id': self.sp_fp.id, + 'invoice_line_ids': [(0, 0, { + 'name': 'service', + 'account_id': self.a_sale.id, + 'quantity': 1, + 'price_unit': 100, + 'invoice_line_tax_ids': [(6, 0, { + self.tax22.id + })] + })] + }) + invoice2.action_invoice_open() + data = { + 'from_date': self.recent_date, + 'to_date': self.recent_date, + } + totals_sp = self.tax22sp._compute_totals_tax(data) + totals = self.tax22._compute_totals_tax(data) + self.assertEqual(totals_sp, (u'22% SP', 100.0, 22.0, 0.0, 0)) + self.assertEqual(totals, (u'22%', 100.0, 22.0, 22.0, 0))