From 2008228129a342409f0a8e7078b35b16becb7fc8 Mon Sep 17 00:00:00 2001 From: Raf Ven Date: Fri, 17 Aug 2018 09:13:58 +0200 Subject: [PATCH] [11.0][MIG] account_fiscal_position_vat_check: Migration to 11.0 --- account_fiscal_position_vat_check/README.rst | 12 +- account_fiscal_position_vat_check/__init__.py | 1 - .../__manifest__.py | 28 ++-- .../models/__init__.py | 1 - .../models/account_invoice.py | 1 - .../models/partner.py | 10 +- .../tests/__init__.py | 3 + .../tests/test_fiscal_position_vat_check.py | 137 ++++++++++++++++++ 8 files changed, 171 insertions(+), 22 deletions(-) create mode 100644 account_fiscal_position_vat_check/tests/__init__.py create mode 100644 account_fiscal_position_vat_check/tests/test_fiscal_position_vat_check.py diff --git a/account_fiscal_position_vat_check/README.rst b/account_fiscal_position_vat_check/README.rst index 612e7907d..eac09ad6c 100644 --- a/account_fiscal_position_vat_check/README.rst +++ b/account_fiscal_position_vat_check/README.rst @@ -1,5 +1,5 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl :alt: License: AGPL-3 ================================= @@ -44,10 +44,18 @@ help us smashing it by providing a detailed and welcomed feedback. Credits ======= +Images +------ + +* Odoo Community Association: `Icon `_. + Contributors ------------ * Alexis de Lattre +* Raf Ven (https://odoo.dynapps.be) + +Do not contact contributors directly about support or help with technical issues. Maintainer ---------- diff --git a/account_fiscal_position_vat_check/__init__.py b/account_fiscal_position_vat_check/__init__.py index cde864bae..a9e337226 100644 --- a/account_fiscal_position_vat_check/__init__.py +++ b/account_fiscal_position_vat_check/__init__.py @@ -1,3 +1,2 @@ -# -*- coding: utf-8 -*- from . import models diff --git a/account_fiscal_position_vat_check/__manifest__.py b/account_fiscal_position_vat_check/__manifest__.py index 1e0234efe..cff5d6acf 100644 --- a/account_fiscal_position_vat_check/__manifest__.py +++ b/account_fiscal_position_vat_check/__manifest__.py @@ -1,18 +1,22 @@ -# -*- coding: utf-8 -*- # © 2013-2016 Akretion (Alexis de Lattre ) +# © 2018 DynApps (Raf Ven ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Account Fiscal Position VAT Check', - 'version': '10.0.1.0.0', - 'category': 'Accounting & Finance', - 'license': 'AGPL-3', - 'summary': 'Check VAT on invoice validation', - 'author': "Akretion,Odoo Community Association (OCA)", - 'website': 'http://www.akretion.com', - 'depends': ['account', 'base_vat'], - 'data': [ - 'views/account_fiscal_position.xml', + "name": "Account Fiscal Position VAT Check", + "version": "11.0.1.0.0", + "category": "Accounting & Finance", + "license": "AGPL-3", + "summary": "Check VAT on invoice validation", + "author": "Akretion, Odoo Community Association (OCA)", + "website": "http://www.akretion.com", + "depends": [ + "account", + "base_vat" ], - 'installable': True, + "data": [ + "views/account_fiscal_position.xml", + ], + "installable": True, + "application": False, } diff --git a/account_fiscal_position_vat_check/models/__init__.py b/account_fiscal_position_vat_check/models/__init__.py index d8b42d60d..58760f723 100644 --- a/account_fiscal_position_vat_check/models/__init__.py +++ b/account_fiscal_position_vat_check/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from . import account_invoice from . import partner diff --git a/account_fiscal_position_vat_check/models/account_invoice.py b/account_fiscal_position_vat_check/models/account_invoice.py index ba616a59f..6c33ebd3d 100644 --- a/account_fiscal_position_vat_check/models/account_invoice.py +++ b/account_fiscal_position_vat_check/models/account_invoice.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2013-2016 Akretion (Alexis de Lattre ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/account_fiscal_position_vat_check/models/partner.py b/account_fiscal_position_vat_check/models/partner.py index a02f68669..7e2545219 100644 --- a/account_fiscal_position_vat_check/models/partner.py +++ b/account_fiscal_position_vat_check/models/partner.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2013-2016 Akretion (Alexis de Lattre ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -9,17 +8,18 @@ class ResPartner(models.Model): _inherit = 'res.partner' @api.onchange('property_account_position_id') - def fiscal_position_change(self): + def onchange_fiscal_position(self): """Warning if the fiscal position requires a VAT number and the partner doesn't have one yet""" - fp = self.property_account_position_id - if fp.vat_required and self.customer and not self.vat: + fiscal_position = self.property_account_position_id + if fiscal_position.vat_required and self.customer and not self.vat: return { 'warning': { 'title': _('Missing VAT number:'), 'message': _( "You have set the fiscal position '%s' " "that require the customer to have a VAT number, " - "but the VAT number is missing.") % fp.name + "but the VAT number is missing." + ) % fiscal_position.name } } diff --git a/account_fiscal_position_vat_check/tests/__init__.py b/account_fiscal_position_vat_check/tests/__init__.py new file mode 100644 index 000000000..110b0a4a8 --- /dev/null +++ b/account_fiscal_position_vat_check/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_fiscal_position_vat_check diff --git a/account_fiscal_position_vat_check/tests/test_fiscal_position_vat_check.py b/account_fiscal_position_vat_check/tests/test_fiscal_position_vat_check.py new file mode 100644 index 000000000..3fd69341e --- /dev/null +++ b/account_fiscal_position_vat_check/tests/test_fiscal_position_vat_check.py @@ -0,0 +1,137 @@ +# Copyright 2018 Raf Ven +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase +from odoo.exceptions import UserError + + +class TestFiscalPositionVatCheck(TransactionCase): + + # pylint: disable=too-many-instance-attributes + def setUp(self): + super(TestFiscalPositionVatCheck, self).setUp() + self._create_fiscal_positions() + self._create_partners() + self._configure_accounting() + + def _create_fiscal_positions(self): + self.fp_b2c = self.env['account.fiscal.position'].create(dict( + name="EU-VAT-B2C", + vat_required=False, + )) + self.fp_b2b = self.env['account.fiscal.position'].create(dict( + name="EU-VAT-B2B", + vat_required=True, + )) + + def _create_partners(self): + self.partner_b2c = self.env['res.partner'].create(dict( + name="Test Partner B2C", + + )) + self.partner_b2b = self.env['res.partner'].create(dict( + name="Test Partner B2B", + vat="BE0477472701", + )) + + def _configure_accounting(self): + self.product = self.env['product.product'].create(dict( + name='product name', + )) + self.account_type1 = self.env['account.account.type'].create(dict( + name='acc type test 1', + type='receivable', + )) + self.account_type2 = self.env['account.account.type'].create(dict( + name='acc type test 2', + type='other', + )) + self.account_account = self.env['account.account'].create(dict( + name='acc test', + code='X2020', + user_type_id=self.account_type1.id, + reconcile=True, + )) + self.account_account_line = self.env['account.account'].create(dict( + name='acc inv line test', + code='X2021', + user_type_id=self.account_type2.id, + reconcile=True, + )) + self.sale_sequence = self.env['ir.sequence'].create(dict( + name='Journal Sale', + prefix='SALE', + padding=6, + company_id=self.env.ref("base.main_company").id, + )) + self.account_journal_sale = self.env['account.journal'].create(dict( + name='Sale journal', + code='SALE', + type='sale', + sequence_id=self.sale_sequence.id + )) + + def create_out_invoice(self, partner): + invoice = self.env['account.invoice'].create(dict( + partner_id=partner.id, + account_id=self.account_account.id, + type='out_invoice', + journal_id=self.account_journal_sale.id, + )) + + self.env['account.invoice.line'].create(dict( + product_id=self.product.id, + quantity=1.0, + price_unit=100.0, + invoice_id=invoice.id, + name='product that cost 100', + account_id=self.account_account_line.id, + )) + return invoice + + def test_fiscal_position_vat_check(self): + # Empty fiscal position should not return a warning + result = self.partner_b2c.onchange_fiscal_position() + self.assertEqual(result, None) + # B2C fiscal position should not return a warning + self.partner_b2c.property_account_position_id = self.fp_b2c + result = self.partner_b2c.onchange_fiscal_position() + self.assertEqual(result, None) + # B2B fiscal position should return a warning + self.partner_b2c.property_account_position_id = self.fp_b2b + result = self.partner_b2c.onchange_fiscal_position() + self.assertEqual(result['warning']['title'], 'Missing VAT number:') + + # Create Invoice for B2C partner with B2C fiscal position + self.partner_b2c.property_account_position_id = self.fp_b2c + invoice = self.create_out_invoice(partner=self.partner_b2c) + invoice.action_invoice_open() + + # Create Invoice for B2C partner with B2B fiscal position + self.partner_b2c.property_account_position_id = self.fp_b2b + invoice = self.create_out_invoice(partner=self.partner_b2c) + err_msg = "But the Customer '.*' doesn't have a VAT number" + with self.assertRaisesRegex(UserError, err_msg): + invoice.action_invoice_open() + + # Empty fiscal position should not return a warning + result = self.partner_b2b.onchange_fiscal_position() + self.assertEqual(result, None) + # B2C fiscal position should not return a warning + self.partner_b2b.property_account_position_id = self.fp_b2c + result = self.partner_b2b.onchange_fiscal_position() + self.assertEqual(result, None) + # B2B fiscal position should return a warning + self.partner_b2b.property_account_position_id = self.fp_b2b + result = self.partner_b2b.onchange_fiscal_position() + self.assertEqual(result, None) + + # Create Invoice for B2B partner with B2B fiscal position + self.partner_b2b.property_account_position_id = self.fp_b2b + invoice = self.create_out_invoice(partner=self.partner_b2b) + invoice.action_invoice_open() + + # Create Invoice for B2B partner with B2C fiscal position + self.partner_b2b.property_account_position_id = self.fp_b2c + invoice = self.create_out_invoice(partner=self.partner_b2b) + invoice.action_invoice_open()