From 3b53f6842ca934336e9f625e1f11c8a7435c5a2d Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Sun, 11 Oct 2020 00:23:33 +0200 Subject: [PATCH] account_fiscal_position_vat_check: black, isort and others --- .../__manifest__.py | 22 ++++----- .../models/account_move.py | 30 +++++++----- .../models/partner.py | 16 ++++--- .../views/account_fiscal_position.xml | 47 ++++++++----------- .../addons/account_fiscal_position_vat_check | 1 + .../setup.py | 6 +++ 6 files changed, 65 insertions(+), 57 deletions(-) create mode 120000 setup/account_fiscal_position_vat_check/odoo/addons/account_fiscal_position_vat_check create mode 100644 setup/account_fiscal_position_vat_check/setup.py diff --git a/account_fiscal_position_vat_check/__manifest__.py b/account_fiscal_position_vat_check/__manifest__.py index 59ef8d1cb..a220f95a9 100644 --- a/account_fiscal_position_vat_check/__manifest__.py +++ b/account_fiscal_position_vat_check/__manifest__.py @@ -3,16 +3,16 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Account Fiscal Position VAT Check', - 'version': '14.0.1.0.0', - 'category': 'Invoices & Payments', - 'license': 'AGPL-3', - 'summary': 'Check VAT on invoice validation', - 'author': "Akretion,Odoo Community Association (OCA)", - 'website': 'https://github.com/OCA/account-financial-tools', - 'depends': ['account', 'base_vat'], - 'data': [ - 'views/account_fiscal_position.xml', + "name": "Account Fiscal Position VAT Check", + "version": "14.0.1.0.0", + "category": "Invoices & Payments", + "license": "AGPL-3", + "summary": "Check VAT on invoice validation", + "author": "Akretion,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-financial-tools", + "depends": ["account", "base_vat"], + "data": [ + "views/account_fiscal_position.xml", ], - 'installable': True, + "installable": True, } diff --git a/account_fiscal_position_vat_check/models/account_move.py b/account_fiscal_position_vat_check/models/account_move.py index 26fdfe821..726b10c32 100644 --- a/account_fiscal_position_vat_check/models/account_move.py +++ b/account_fiscal_position_vat_check/models/account_move.py @@ -2,27 +2,33 @@ # @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, _ +from odoo import _, models from odoo.exceptions import UserError class AccountMove(models.Model): - _inherit = 'account.move' + _inherit = "account.move" def _post(self, soft=True): """Check that the customer has VAT set if required by the fiscal position""" for move in self: if ( - 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.") % ( + 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." + ) + % ( move.fiscal_position_id.display_name, - move.commercial_partner_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 8f40d24e7..5e76aafa2 100644 --- a/account_fiscal_position_vat_check/models/partner.py +++ b/account_fiscal_position_vat_check/models/partner.py @@ -2,25 +2,27 @@ # @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, models, _ +from odoo import _, api, models class ResPartner(models.Model): - _inherit = 'res.partner' + _inherit = "res.partner" - @api.onchange('property_account_position_id') + @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_id if fp.vat_required and not self.vat: return { - 'warning': { - 'title': _('Missing VAT number:'), - 'message': _( + "warning": { + "title": _("Missing VAT number:"), + "message": _( "You have set the fiscal position '%s' " "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 + "should add its VAT number." + ) + % fp.display_name, } } 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 eaf3951e4..99d0c9845 100644 --- a/account_fiscal_position_vat_check/views/account_fiscal_position.xml +++ b/account_fiscal_position_vat_check/views/account_fiscal_position.xml @@ -1,36 +1,29 @@ - + - - - - - customer.must.have.vat.fiscal_position_form - account.fiscal.position - - - - - {} + + customer.must.have.vat.fiscal_position_form + account.fiscal.position + + + + + {} + - - - - - - customer.must.have.vat.fiscal_position_tree - account.fiscal.position - - - - + + + customer.must.have.vat.fiscal_position_tree + account.fiscal.position + + + + + - - - - + diff --git a/setup/account_fiscal_position_vat_check/odoo/addons/account_fiscal_position_vat_check b/setup/account_fiscal_position_vat_check/odoo/addons/account_fiscal_position_vat_check new file mode 120000 index 000000000..bc7f615f3 --- /dev/null +++ b/setup/account_fiscal_position_vat_check/odoo/addons/account_fiscal_position_vat_check @@ -0,0 +1 @@ +../../../../account_fiscal_position_vat_check \ No newline at end of file diff --git a/setup/account_fiscal_position_vat_check/setup.py b/setup/account_fiscal_position_vat_check/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_fiscal_position_vat_check/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)