From 9474eef4317615f28a30a8cfbf813367c17a065a Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 7 Oct 2014 22:17:18 +0200 Subject: [PATCH] Port to v8 and to new API --- .../__init__.py | 2 +- .../__openerp__.py | 29 +++++-------- .../account_fiscal_position_view.xml | 4 +- .../account_invoice.py | 41 ++++++++---------- .../account_fiscal_position_vat_check.pot | 0 .../i18n/fr.po | 0 .../i18n/pt_BR.po | 0 .../partner.py | 27 ++++++------ .../partner_view.xml | 2 +- .../description}/fiscal_position_form.jpg | Bin .../vat_check_invoice_validation.jpg | Bin 11 files changed, 46 insertions(+), 59 deletions(-) rename {__unported__/account_fiscal_position_vat_check => account_fiscal_position_vat_check}/__init__.py (94%) rename {__unported__/account_fiscal_position_vat_check => account_fiscal_position_vat_check}/__openerp__.py (74%) rename {__unported__/account_fiscal_position_vat_check => account_fiscal_position_vat_check}/account_fiscal_position_view.xml (89%) rename {__unported__/account_fiscal_position_vat_check => account_fiscal_position_vat_check}/account_invoice.py (67%) rename {__unported__/account_fiscal_position_vat_check => account_fiscal_position_vat_check}/i18n/account_fiscal_position_vat_check.pot (100%) rename {__unported__/account_fiscal_position_vat_check => account_fiscal_position_vat_check}/i18n/fr.po (100%) rename {__unported__/account_fiscal_position_vat_check => account_fiscal_position_vat_check}/i18n/pt_BR.po (100%) rename {__unported__/account_fiscal_position_vat_check => account_fiscal_position_vat_check}/partner.py (67%) rename {__unported__/account_fiscal_position_vat_check => account_fiscal_position_vat_check}/partner_view.xml (91%) rename {__unported__/account_fiscal_position_vat_check/images => account_fiscal_position_vat_check/static/description}/fiscal_position_form.jpg (100%) rename {__unported__/account_fiscal_position_vat_check/images => account_fiscal_position_vat_check/static/description}/vat_check_invoice_validation.jpg (100%) diff --git a/__unported__/account_fiscal_position_vat_check/__init__.py b/account_fiscal_position_vat_check/__init__.py similarity index 94% rename from __unported__/account_fiscal_position_vat_check/__init__.py rename to account_fiscal_position_vat_check/__init__.py index 299cab6fa..871d74b5b 100644 --- a/__unported__/account_fiscal_position_vat_check/__init__.py +++ b/account_fiscal_position_vat_check/__init__.py @@ -2,7 +2,7 @@ ############################################################################## # # Account Fiscal Position VAT Check module for OpenERP -# Copyright (C) 2013 Akretion (http://www.akretion.com) +# 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 diff --git a/__unported__/account_fiscal_position_vat_check/__openerp__.py b/account_fiscal_position_vat_check/__openerp__.py similarity index 74% rename from __unported__/account_fiscal_position_vat_check/__openerp__.py rename to account_fiscal_position_vat_check/__openerp__.py index bc7c3c852..41be4d437 100644 --- a/__unported__/account_fiscal_position_vat_check/__openerp__.py +++ b/account_fiscal_position_vat_check/__openerp__.py @@ -2,7 +2,7 @@ ############################################################################## # # Account Fiscal Position VAT Check module for OpenERP -# Copyright (C) 2013 Akretion (http://www.akretion.com) +# 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 @@ -33,27 +33,23 @@ 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. +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. +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. +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. +for any help or question about this module. """, 'author': 'Akretion', 'website': 'http://www.akretion.com', @@ -62,11 +58,6 @@ Please contact Alexis de Lattre from Akretion 'account_fiscal_position_view.xml', 'partner_view.xml', ], - 'images': [ - 'images/fiscal_position_form.jpg', - 'images/vat_check_invoice_validation.jpg', - ], - 'installable': False, - 'active': False, + 'installable': True, 'application': True, } diff --git a/__unported__/account_fiscal_position_vat_check/account_fiscal_position_view.xml b/account_fiscal_position_vat_check/account_fiscal_position_view.xml similarity index 89% rename from __unported__/account_fiscal_position_vat_check/account_fiscal_position_view.xml rename to account_fiscal_position_vat_check/account_fiscal_position_view.xml index d29e2b14b..292070ba7 100644 --- a/__unported__/account_fiscal_position_vat_check/account_fiscal_position_view.xml +++ b/account_fiscal_position_vat_check/account_fiscal_position_view.xml @@ -1,7 +1,7 @@ @@ -15,7 +15,7 @@ account.fiscal.position - + diff --git a/__unported__/account_fiscal_position_vat_check/account_invoice.py b/account_fiscal_position_vat_check/account_invoice.py similarity index 67% rename from __unported__/account_fiscal_position_vat_check/account_invoice.py rename to account_fiscal_position_vat_check/account_invoice.py index c3a77a471..0097af6de 100644 --- a/__unported__/account_fiscal_position_vat_check/account_invoice.py +++ b/account_fiscal_position_vat_check/account_invoice.py @@ -2,7 +2,7 @@ ############################################################################## # # Account Fiscal Position VAT Check module for OpenERP -# Copyright (C) 2013 Akretion (http://www.akretion.com) +# 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 @@ -20,39 +20,37 @@ # ############################################################################## -from openerp.osv import orm, fields -from openerp.tools.translate import _ +from openerp import models, fields, api, _ +from openerp.exceptions import except_orm -class account_fiscal_position(orm.Model): +class account_fiscal_position(models.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." - ), - } + customer_must_have_vat = fields.Boolean( + string='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): +class account_invoice(models.Model): _inherit = 'account.invoice' - def action_move_create(self, cr, uid, ids, context=None): + @api.multi + def action_move_create(self): '''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: + 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 orm.except_orm( + raise except_orm( _('Missing VAT number:'), _("You are trying to validate %s " "with the fiscal position '%s' " @@ -63,5 +61,4 @@ class account_invoice(orm.Model): " 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) + return super(account_invoice, self).action_move_create() diff --git a/__unported__/account_fiscal_position_vat_check/i18n/account_fiscal_position_vat_check.pot b/account_fiscal_position_vat_check/i18n/account_fiscal_position_vat_check.pot similarity index 100% rename from __unported__/account_fiscal_position_vat_check/i18n/account_fiscal_position_vat_check.pot rename to account_fiscal_position_vat_check/i18n/account_fiscal_position_vat_check.pot diff --git a/__unported__/account_fiscal_position_vat_check/i18n/fr.po b/account_fiscal_position_vat_check/i18n/fr.po similarity index 100% rename from __unported__/account_fiscal_position_vat_check/i18n/fr.po rename to account_fiscal_position_vat_check/i18n/fr.po diff --git a/__unported__/account_fiscal_position_vat_check/i18n/pt_BR.po b/account_fiscal_position_vat_check/i18n/pt_BR.po similarity index 100% rename from __unported__/account_fiscal_position_vat_check/i18n/pt_BR.po rename to account_fiscal_position_vat_check/i18n/pt_BR.po diff --git a/__unported__/account_fiscal_position_vat_check/partner.py b/account_fiscal_position_vat_check/partner.py similarity index 67% rename from __unported__/account_fiscal_position_vat_check/partner.py rename to account_fiscal_position_vat_check/partner.py index c4bc8f722..4cc6ed60c 100644 --- a/__unported__/account_fiscal_position_vat_check/partner.py +++ b/account_fiscal_position_vat_check/partner.py @@ -2,7 +2,7 @@ ############################################################################## # # Account Fiscal Position VAT Check module for OpenERP -# Copyright (C) 2013 Akretion (http://www.akretion.com) +# 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 @@ -20,21 +20,21 @@ # ############################################################################## -from openerp.osv import orm -from openerp.tools.translate import _ +from openerp import models, api, _ -class res_partner(orm.Model): +class res_partner(models.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']: + @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:'), @@ -42,8 +42,7 @@ class res_partner(orm.Model): "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'] + " in OpenERP.") % fp.name } } return True diff --git a/__unported__/account_fiscal_position_vat_check/partner_view.xml b/account_fiscal_position_vat_check/partner_view.xml similarity index 91% rename from __unported__/account_fiscal_position_vat_check/partner_view.xml rename to account_fiscal_position_vat_check/partner_view.xml index c7b6abee7..650540c05 100644 --- a/__unported__/account_fiscal_position_vat_check/partner_view.xml +++ b/account_fiscal_position_vat_check/partner_view.xml @@ -1,7 +1,7 @@ diff --git a/__unported__/account_fiscal_position_vat_check/images/fiscal_position_form.jpg b/account_fiscal_position_vat_check/static/description/fiscal_position_form.jpg similarity index 100% rename from __unported__/account_fiscal_position_vat_check/images/fiscal_position_form.jpg rename to account_fiscal_position_vat_check/static/description/fiscal_position_form.jpg diff --git a/__unported__/account_fiscal_position_vat_check/images/vat_check_invoice_validation.jpg b/account_fiscal_position_vat_check/static/description/vat_check_invoice_validation.jpg similarity index 100% rename from __unported__/account_fiscal_position_vat_check/images/vat_check_invoice_validation.jpg rename to account_fiscal_position_vat_check/static/description/vat_check_invoice_validation.jpg