mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Port to v8 and to new API
This commit is contained in:
@@ -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 <alexis.delattre@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
@@ -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 <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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 <alexis.delattre@akretion.com>
|
||||
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 <alexis.delattre@akretion.com>
|
||||
'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,
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Copyright (C) 2013 Akretion (http://www.akretion.com/)
|
||||
Copyright (C) 2013-2014 Akretion (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
@@ -15,7 +15,7 @@
|
||||
<field name="model">account.fiscal.position</field>
|
||||
<field name="inherit_id" ref="account.view_account_position_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="active" position="after">
|
||||
<field name="country_group_id" position="after">
|
||||
<field name="customer_must_have_vat" />
|
||||
</field>
|
||||
</field>
|
||||
@@ -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 <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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()
|
||||
@@ -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 <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Copyright (C) 2013 Akretion (http://www.akretion.com/)
|
||||
Copyright (C) 2013-2014 Akretion (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
Reference in New Issue
Block a user