From 0817db56ab768cf436660e9baca68f1b3d90474d Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 11 Oct 2016 12:09:26 +0200 Subject: [PATCH] 10.0 Port account_fiscal_position_vat_check (#408) [MIG] account_fiscal_position_vat_check: to v10 --- account_fiscal_position_vat_check/README.rst | 65 +++++++++++++++++++ account_fiscal_position_vat_check/__init__.py | 25 +------ .../__manifest__.py | 56 ++-------------- .../account_invoice.py | 64 ------------------ .../models/__init__.py | 4 ++ .../models/account_invoice.py | 29 +++++++++ .../models/partner.py | 25 +++++++ account_fiscal_position_vat_check/partner.py | 47 -------------- .../partner_view.xml | 26 -------- .../account_fiscal_position.xml} | 20 +++--- 10 files changed, 140 insertions(+), 221 deletions(-) create mode 100644 account_fiscal_position_vat_check/README.rst delete mode 100644 account_fiscal_position_vat_check/account_invoice.py create mode 100644 account_fiscal_position_vat_check/models/__init__.py create mode 100644 account_fiscal_position_vat_check/models/account_invoice.py create mode 100644 account_fiscal_position_vat_check/models/partner.py delete mode 100644 account_fiscal_position_vat_check/partner.py delete mode 100644 account_fiscal_position_vat_check/partner_view.xml rename account_fiscal_position_vat_check/{account_fiscal_position_view.xml => views/account_fiscal_position.xml} (67%) diff --git a/account_fiscal_position_vat_check/README.rst b/account_fiscal_position_vat_check/README.rst new file mode 100644 index 000000000..612e7907d --- /dev/null +++ b/account_fiscal_position_vat_check/README.rst @@ -0,0 +1,65 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================================= +Account Fiscal Position VAT Check +================================= + +With this module, when a user tries to validate a customer invoice or refund +with a fiscal position that requires VAT, Odoo block the validation of the invoice +if the customer doesn't have a VAT number in Odoo. + +In the European Union (EU), when an EU company sends an invoice to +another EU company in another country, it can invoice without VAT +(most of the time) but the VAT number of the customer must be displayed +on the invoice. + +Configuration +============= + +To configure this module, go to *Accounting > Configuration > Accounting +> Fiscal Positions* and enable the option **VAT Required** on the relevant +fiscal positions. + +Usage +===== + +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 +that doesn't have a VAT number yet. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/92/10.0 + +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. + +Credits +======= + +Contributors +------------ + +* Alexis de Lattre + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/account_fiscal_position_vat_check/__init__.py b/account_fiscal_position_vat_check/__init__.py index e665809a4..cde864bae 100644 --- a/account_fiscal_position_vat_check/__init__.py +++ b/account_fiscal_position_vat_check/__init__.py @@ -1,24 +1,3 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Account Fiscal Position VAT Check module for Odoo -# Copyright (C) 2013-2014 Akretion (http://www.akretion.com) -# @author Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- -from . import account_invoice -from . import partner +from . import models diff --git a/account_fiscal_position_vat_check/__manifest__.py b/account_fiscal_position_vat_check/__manifest__.py index 58099f813..1e0234efe 100644 --- a/account_fiscal_position_vat_check/__manifest__.py +++ b/account_fiscal_position_vat_check/__manifest__.py @@ -1,62 +1,18 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Account Fiscal Position VAT Check module for Odoo -# Copyright (C) 2013-2014 Akretion (http://www.akretion.com) -# @author Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - +# -*- coding: utf-8 -*- +# © 2013-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Account Fiscal Position VAT Check', - 'version': '8.0.0.1.1', + 'version': '10.0.1.0.0', 'category': 'Accounting & Finance', 'license': 'AGPL-3', 'summary': 'Check VAT on invoice validation', - 'description': """ -Check that the Customer has a VAT number on invoice validation -============================================================== - -This module adds an option **Customer must have VAT** on fiscal positions. -When a user tries to validate a customer invoice or refund -with a fiscal position that have this option, OpenERP will check that -the customer has a VAT number. - -If it doesn't, OpenERP will block the validation of the invoice -and display an error message. - -In the European Union (EU), when an EU company sends an invoice to -another EU company in another country, it can invoice without VAT -(most of the time) but the VAT number of the customer must be displayed -on the invoice. - -This module also displays a warning when a user sets -a fiscal position with the option **Customer must have VAT** on a customer -and this customer doesn't have a VAT number in OpenERP yet. - -Please contact Alexis de Lattre from Akretion -for any help or question about this module. - """, 'author': "Akretion,Odoo Community Association (OCA)", 'website': 'http://www.akretion.com', 'depends': ['account', 'base_vat'], 'data': [ - 'account_fiscal_position_view.xml', - 'partner_view.xml', + 'views/account_fiscal_position.xml', ], - 'installable': False, + 'installable': True, } diff --git a/account_fiscal_position_vat_check/account_invoice.py b/account_fiscal_position_vat_check/account_invoice.py deleted file mode 100644 index 62a17a7d2..000000000 --- a/account_fiscal_position_vat_check/account_invoice.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Account Fiscal Position VAT Check module for OpenERP -# Copyright (C) 2013-2014 Akretion (http://www.akretion.com) -# @author Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from openerp import models, fields, api, _ -from openerp.exceptions import except_orm - - -class account_fiscal_position(models.Model): - _inherit = 'account.fiscal.position' - - customer_must_have_vat = fields.Boolean( - string='Customer Must Have VAT number', - help="If enabled, Odoo will check that the customer has a VAT " - "number when the user validates a customer invoice/refund.") - - -class account_invoice(models.Model): - _inherit = 'account.invoice' - - @api.multi - def action_move_create(self): - '''Check that the customer has VAT set - if required by the fiscal position''' - for invoice in self: - if ( - invoice.type in ('out_invoice', 'out_refund') and - invoice.fiscal_position and - invoice.fiscal_position.customer_must_have_vat and - not invoice.partner_id.vat): - if invoice.type == 'out_invoice': - type_label = _('a Customer Invoice') - else: - type_label = _('a Customer Refund') - raise except_orm( - _('Missing VAT number:'), - _("You are trying to validate %s " - "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 OpenERP." - "Please add the VAT number of this Customer in Odoo " - " and try to validate again.") - % (type_label, invoice.fiscal_position.name, - invoice.partner_id.name)) - return super(account_invoice, self).action_move_create() diff --git a/account_fiscal_position_vat_check/models/__init__.py b/account_fiscal_position_vat_check/models/__init__.py new file mode 100644 index 000000000..d8b42d60d --- /dev/null +++ b/account_fiscal_position_vat_check/models/__init__.py @@ -0,0 +1,4 @@ +# -*- 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 new file mode 100644 index 000000000..ba616a59f --- /dev/null +++ b/account_fiscal_position_vat_check/models/account_invoice.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# © 2013-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, api, _ +from odoo.exceptions import UserError + + +class AccountInvoice(models.Model): + _inherit = 'account.invoice' + + @api.multi + def action_move_create(self): + """Check that the customer has VAT set if required by the + fiscal position""" + for invoice in self: + if ( + invoice.type in ('out_invoice', 'out_refund') and + invoice.fiscal_position_id.vat_required and + not invoice.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.name_get()[0][1])) + return super(AccountInvoice, self).action_move_create() diff --git a/account_fiscal_position_vat_check/models/partner.py b/account_fiscal_position_vat_check/models/partner.py new file mode 100644 index 000000000..a02f68669 --- /dev/null +++ b/account_fiscal_position_vat_check/models/partner.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# © 2013-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, api, _ + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + @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 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 + } + } diff --git a/account_fiscal_position_vat_check/partner.py b/account_fiscal_position_vat_check/partner.py deleted file mode 100644 index 656ca127d..000000000 --- a/account_fiscal_position_vat_check/partner.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Account Fiscal Position VAT Check module for Odoo -# Copyright (C) 2013-2014 Akretion (http://www.akretion.com) -# @author Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from openerp import models, api, _ - - -class res_partner(models.Model): - _inherit = 'res.partner' - - @api.multi - def fiscal_position_change( - self, account_position_id, vat, customer): - '''Warning if the fiscal position requires a VAT number and the - partner doesn't have one yet''' - if account_position_id and customer and not vat: - fp = self.env['account.fiscal.position'].browse( - account_position_id) - if fp.customer_must_have_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 - } - } - return True diff --git a/account_fiscal_position_vat_check/partner_view.xml b/account_fiscal_position_vat_check/partner_view.xml deleted file mode 100644 index 650540c05..000000000 --- a/account_fiscal_position_vat_check/partner_view.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - customer.must.have.vat.fiscal_position_form - res.partner - - - - fiscal_position_change(property_account_position, vat, customer) - - - - - - - diff --git a/account_fiscal_position_vat_check/account_fiscal_position_view.xml b/account_fiscal_position_vat_check/views/account_fiscal_position.xml similarity index 67% rename from account_fiscal_position_vat_check/account_fiscal_position_view.xml rename to account_fiscal_position_vat_check/views/account_fiscal_position.xml index 292070ba7..d5e793752 100644 --- a/account_fiscal_position_vat_check/account_fiscal_position_view.xml +++ b/account_fiscal_position_vat_check/views/account_fiscal_position.xml @@ -1,13 +1,10 @@ - - - + @@ -15,8 +12,9 @@ account.fiscal.position - - + + + {} @@ -28,10 +26,10 @@ - + - - + +