From 32073277ab150ffe83a1d38b62dbc2e4669e2493 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Sun, 11 Oct 2020 00:22:05 +0200 Subject: [PATCH] [MIG] account_fiscal_position_vat_check from v12 to v14 --- .../__manifest__.py | 4 +-- .../models/__init__.py | 2 +- .../{account_invoice.py => account_move.py} | 25 +++++++++---------- .../models/partner.py | 9 ++++--- .../readme/USAGE.rst | 4 +-- .../views/account_fiscal_position.xml | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) rename account_fiscal_position_vat_check/models/{account_invoice.py => account_move.py} (53%) diff --git a/account_fiscal_position_vat_check/__manifest__.py b/account_fiscal_position_vat_check/__manifest__.py index e06f77a0..59ef8d1c 100644 --- a/account_fiscal_position_vat_check/__manifest__.py +++ b/account_fiscal_position_vat_check/__manifest__.py @@ -1,10 +1,10 @@ -# Copyright 2013-2019 Akretion France (https://akretion.com/) +# Copyright 2013-2020 Akretion France (https://akretion.com/) # @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Account Fiscal Position VAT Check', - 'version': '12.0.1.0.0', + 'version': '14.0.1.0.0', 'category': 'Invoices & Payments', 'license': 'AGPL-3', 'summary': 'Check VAT on invoice validation', diff --git a/account_fiscal_position_vat_check/models/__init__.py b/account_fiscal_position_vat_check/models/__init__.py index eca73eb1..2cf57a71 100644 --- a/account_fiscal_position_vat_check/models/__init__.py +++ b/account_fiscal_position_vat_check/models/__init__.py @@ -1,2 +1,2 @@ -from . import account_invoice +from . import account_move from . import partner diff --git a/account_fiscal_position_vat_check/models/account_invoice.py b/account_fiscal_position_vat_check/models/account_move.py similarity index 53% rename from account_fiscal_position_vat_check/models/account_invoice.py rename to account_fiscal_position_vat_check/models/account_move.py index 7e7031dd..26fdfe82 100644 --- a/account_fiscal_position_vat_check/models/account_invoice.py +++ b/account_fiscal_position_vat_check/models/account_move.py @@ -1,29 +1,28 @@ -# Copyright 2013-2019 Akretion France (https://akretion.com/) +# Copyright 2013-2020 Akretion France (https://akretion.com/) # @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, models, _ +from odoo import models, _ from odoo.exceptions import UserError -class AccountInvoice(models.Model): - _inherit = 'account.invoice' +class AccountMove(models.Model): + _inherit = 'account.move' - @api.multi - def action_move_create(self): + def _post(self, soft=True): """Check that the customer has VAT set if required by the fiscal position""" - for invoice in self: + for move in self: if ( - invoice.type in ('out_invoice', 'out_refund') and - invoice.fiscal_position_id.vat_required and - not invoice.partner_id.vat): + move.move_type in ('out_invoice', 'out_refund') and + move.fiscal_position_id.vat_required and + not move.commercial_partner_id.vat): raise UserError(_( "You are trying to validate a customer invoice/refund " "with the fiscal position '%s' that require the customer " "to have a VAT number. But the Customer '%s' doesn't have " "a VAT number in Odoo. Please add the VAT number of this " "Customer in Odoo and try to validate again.") % ( - invoice.fiscal_position_id.name, - invoice.partner_id.display_name)) - return super(AccountInvoice, self).action_move_create() + move.fiscal_position_id.display_name, + move.commercial_partner_id.display_name)) + return super()._post(soft=soft) diff --git a/account_fiscal_position_vat_check/models/partner.py b/account_fiscal_position_vat_check/models/partner.py index a45d1ffc..8f40d24e 100644 --- a/account_fiscal_position_vat_check/models/partner.py +++ b/account_fiscal_position_vat_check/models/partner.py @@ -1,4 +1,4 @@ -# Copyright 2013-2019 Akretion France (https://akretion.com/) +# Copyright 2013-2020 Akretion France (https://akretion.com/) # @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -13,13 +13,14 @@ class ResPartner(models.Model): """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: + if fp.vat_required 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 + "that require customers to have a VAT number. " + "If you plan to use this partner as a customer, you " + "should add its VAT number.") % fp.display_name } } diff --git a/account_fiscal_position_vat_check/readme/USAGE.rst b/account_fiscal_position_vat_check/readme/USAGE.rst index cef216cd..ea821cf3 100644 --- a/account_fiscal_position_vat_check/readme/USAGE.rst +++ b/account_fiscal_position_vat_check/readme/USAGE.rst @@ -1,3 +1,3 @@ -On the customer form view, Odoo will display a warning when a user sets -a fiscal position that has the option **VAT Required** on a customer +On the partner form view, Odoo will display a warning when a user sets +a fiscal position that has the option **VAT Required** on a partner that doesn't have a VAT number yet. diff --git a/account_fiscal_position_vat_check/views/account_fiscal_position.xml b/account_fiscal_position_vat_check/views/account_fiscal_position.xml index 9f61d938..eaf3951e 100644 --- a/account_fiscal_position_vat_check/views/account_fiscal_position.xml +++ b/account_fiscal_position_vat_check/views/account_fiscal_position.xml @@ -1,6 +1,6 @@