From a9a280d9418a6f8fd9df3686b3e0e02a1797b3a4 Mon Sep 17 00:00:00 2001 From: Nicolas Bessi Date: Thu, 10 Jul 2014 15:52:25 +0200 Subject: [PATCH] [FIX] flake8 PEP8 for module account_fiscal_position_vat_check --- .../__openerp__.py | 64 +++++++++++++++++++ .../account_invoice.py | 64 +++++++++++++++++++ account_fiscal_position_vat_check/partner.py | 47 ++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 account_fiscal_position_vat_check/__openerp__.py create mode 100644 account_fiscal_position_vat_check/account_invoice.py create mode 100644 account_fiscal_position_vat_check/partner.py diff --git a/account_fiscal_position_vat_check/__openerp__.py b/account_fiscal_position_vat_check/__openerp__.py new file mode 100644 index 000000000..55e296ee3 --- /dev/null +++ b/account_fiscal_position_vat_check/__openerp__.py @@ -0,0 +1,64 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Fiscal Position VAT Check module for OpenERP +# Copyright (C) 2013 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 . +# +############################################################################## + + +{ + 'name': 'Account Fiscal Position VAT Check', + 'version': '0.1', + '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', + 'website': 'http://www.akretion.com', + 'depends': ['account'], + 'data': [ + 'account_fiscal_position_view.xml', + 'partner_view.xml', + ], + 'images': [ + 'images/fiscal_position_form.jpg', + 'images/vat_check_invoice_validation.jpg', + ], + 'installable': True, + 'active': False, + 'application': True, +} \ No newline at end of file diff --git a/account_fiscal_position_vat_check/account_invoice.py b/account_fiscal_position_vat_check/account_invoice.py new file mode 100644 index 000000000..05c3b6c63 --- /dev/null +++ b/account_fiscal_position_vat_check/account_invoice.py @@ -0,0 +1,64 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Fiscal Position VAT Check module for OpenERP +# Copyright (C) 2013 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.osv import orm, fields +from openerp.tools.translate import _ + + +class account_fiscal_position(orm.Model): + _inherit = 'account.fiscal.position' + + _columns = { + 'customer_must_have_vat': fields.boolean( + 'Customer Must Have VAT number', + help="If enabled, OpenERP will check that the customer has a VAT number " + "when the user validates a customer invoice/refund." + ), + } + + +class account_invoice(orm.Model): + _inherit = 'account.invoice' + + def action_move_create(self, cr, uid, ids, context=None): + '''Check that the customer has VAT set + if required by the fiscal position''' + for invoice in self.browse(cr, uid, ids, context=context): + 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 orm.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 OpenERP " + " and try to validate again.") + % (type_label, invoice.fiscal_position.name, + invoice.partner_id.name)) + return super(account_invoice, self).action_move_create( + cr, uid, ids, context=context) \ No newline at end of file diff --git a/account_fiscal_position_vat_check/partner.py b/account_fiscal_position_vat_check/partner.py new file mode 100644 index 000000000..86d8747b3 --- /dev/null +++ b/account_fiscal_position_vat_check/partner.py @@ -0,0 +1,47 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Fiscal Position VAT Check module for OpenERP +# Copyright (C) 2013 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.osv import orm +from openerp.tools.translate import _ + + +class res_partner(orm.Model): + _inherit = 'res.partner' + + def fiscal_position_change(self, cr, uid, ids, account_position, vat, customer): + '''Warning is the fiscal position requires a vat number and the partner + doesn't have one yet''' + if account_position and customer and not vat: + fp = self.pool['account.fiscal.position'].read( + cr, uid, account_position, ['customer_must_have_vat', 'name']) + 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. " + "You should add the VAT number of this customer in OpenERP." + ) % fp['name'] + } + } + return True \ No newline at end of file