From 72e734536bd63ae9d5cc365a5e402b0b888d1f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20B=C3=A9lorgey?= Date: Sat, 7 Jan 2017 17:09:15 +0100 Subject: [PATCH] [9.0][FIX] account_fiscal_position_vat_check: vat required not check in partner form (#432) --- .../models/partner.py | 4 ++-- .../tests/__init__.py | 3 +++ .../test_account_fiscal_position_vat_check.py | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 account_fiscal_position_vat_check/tests/__init__.py create mode 100644 account_fiscal_position_vat_check/tests/test_account_fiscal_position_vat_check.py diff --git a/account_fiscal_position_vat_check/models/partner.py b/account_fiscal_position_vat_check/models/partner.py index 6bc8c1c99..e737b633a 100644 --- a/account_fiscal_position_vat_check/models/partner.py +++ b/account_fiscal_position_vat_check/models/partner.py @@ -9,11 +9,11 @@ from openerp import models, api, _ class ResPartner(models.Model): _inherit = 'res.partner' - @api.onchange('property_account_position') + @api.onchange('property_account_position_id') def fiscal_position_change(self): """Warning if the fiscal position requires a VAT number and the partner doesn't have one yet""" - fp = self.property_account_position + fp = self.property_account_position_id if fp.customer_must_have_vat and self.customer and not self.vat: return { 'warning': { 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..a8d041c0b --- /dev/null +++ b/account_fiscal_position_vat_check/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import test_account_fiscal_position_vat_check diff --git a/account_fiscal_position_vat_check/tests/test_account_fiscal_position_vat_check.py b/account_fiscal_position_vat_check/tests/test_account_fiscal_position_vat_check.py new file mode 100644 index 000000000..b89ee9208 --- /dev/null +++ b/account_fiscal_position_vat_check/tests/test_account_fiscal_position_vat_check.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Laurent Bélorgey +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp.tests.common import TransactionCase + + +class TestAccountFiscalPositionVatCheck(TransactionCase): + def test_partner_must_have_vat_check(self): + fp = self.env['account.fiscal.position'].create({ + 'name': 'Test', + 'customer_must_have_vat': True}) + customer = self.env['res.partner'].search( + [('customer', '=', True)], limit=1) + customer.write({'property_account_position_id': fp.id}) + res = customer.fiscal_position_change() + self.assertEqual(res['warning']['title'], 'Missing VAT number:') + fp.write({'customer_must_have_vat': False}) + res = customer.fiscal_position_change() + self.assertFalse(res)