From 8ef89d48cb175c8b767805395d0f4f57a8589f59 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 18 Oct 2016 15:23:58 +0200 Subject: [PATCH] Use @api.onchange instead of on_change in view Move description from __openerp__.py to README --- account_fiscal_position_vat_check/README.rst | 65 +++++++++++++++++++ account_fiscal_position_vat_check/__init__.py | 22 +------ .../__openerp__.py | 52 ++------------- .../account_fiscal_position_view.xml | 5 +- .../account_invoice.py | 30 ++------- account_fiscal_position_vat_check/partner.py | 58 +++++------------ .../partner_view.xml | 26 -------- 7 files changed, 96 insertions(+), 162 deletions(-) create mode 100644 account_fiscal_position_vat_check/README.rst delete mode 100644 account_fiscal_position_vat_check/partner_view.xml diff --git a/account_fiscal_position_vat_check/README.rst b/account_fiscal_position_vat_check/README.rst new file mode 100644 index 000000000..94027d459 --- /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 **Customer Must Have VAT number** +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 **Customer Must Have VAT number** +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/8.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..d8b42d60d 100644 --- a/account_fiscal_position_vat_check/__init__.py +++ b/account_fiscal_position_vat_check/__init__.py @@ -1,24 +1,4 @@ -# -*- 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 diff --git a/account_fiscal_position_vat_check/__openerp__.py b/account_fiscal_position_vat_check/__openerp__.py index 58099f813..9d2facda0 100644 --- a/account_fiscal_position_vat_check/__openerp__.py +++ b/account_fiscal_position_vat_check/__openerp__.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': '8.0.0.1.2', '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', ], 'installable': False, } diff --git a/account_fiscal_position_vat_check/account_fiscal_position_view.xml b/account_fiscal_position_vat_check/account_fiscal_position_view.xml index 292070ba7..353612407 100644 --- a/account_fiscal_position_vat_check/account_fiscal_position_view.xml +++ b/account_fiscal_position_vat_check/account_fiscal_position_view.xml @@ -1,9 +1,8 @@ diff --git a/account_fiscal_position_vat_check/account_invoice.py b/account_fiscal_position_vat_check/account_invoice.py index 62a17a7d2..78cb4d058 100644 --- a/account_fiscal_position_vat_check/account_invoice.py +++ b/account_fiscal_position_vat_check/account_invoice.py @@ -1,30 +1,12 @@ -# -*- 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 . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2013-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp import models, fields, api, _ from openerp.exceptions import except_orm -class account_fiscal_position(models.Model): +class AccountFiscalPosition(models.Model): _inherit = 'account.fiscal.position' customer_must_have_vat = fields.Boolean( @@ -33,7 +15,7 @@ class account_fiscal_position(models.Model): "number when the user validates a customer invoice/refund.") -class account_invoice(models.Model): +class AccountInvoice(models.Model): _inherit = 'account.invoice' @api.multi @@ -61,4 +43,4 @@ class account_invoice(models.Model): " and try to validate again.") % (type_label, invoice.fiscal_position.name, invoice.partner_id.name)) - return super(account_invoice, self).action_move_create() + return super(AccountInvoice, self).action_move_create() diff --git a/account_fiscal_position_vat_check/partner.py b/account_fiscal_position_vat_check/partner.py index 656ca127d..c9a96eee3 100644 --- a/account_fiscal_position_vat_check/partner.py +++ b/account_fiscal_position_vat_check/partner.py @@ -1,47 +1,25 @@ -# -*- 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). from openerp import models, api, _ -class res_partner(models.Model): +class ResPartner(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 - } + @api.onchange('property_account_position') + 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 + if fp.customer_must_have_vat 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 } - 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) - - - - - - -