mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
10.0 Port account_fiscal_position_vat_check (#408)
[MIG] account_fiscal_position_vat_check: to v10
This commit is contained in:
committed by
Pedro M. Baeza
parent
da1a844a77
commit
0817db56ab
65
account_fiscal_position_vat_check/README.rst
Normal file
65
account_fiscal_position_vat_check/README.rst
Normal file
@@ -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
|
||||
<https://github.com/OCA/account-financial-tools/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 <alexis.delattre@akretion.com>
|
||||
|
||||
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.
|
||||
@@ -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 <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import account_invoice
|
||||
from . import partner
|
||||
from . import models
|
||||
|
||||
@@ -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 <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2013-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# 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 <alexis.delattre@akretion.com>
|
||||
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,
|
||||
}
|
||||
|
||||
@@ -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 <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
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()
|
||||
4
account_fiscal_position_vat_check/models/__init__.py
Normal file
4
account_fiscal_position_vat_check/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import account_invoice
|
||||
from . import partner
|
||||
29
account_fiscal_position_vat_check/models/account_invoice.py
Normal file
29
account_fiscal_position_vat_check/models/account_invoice.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2013-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# 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()
|
||||
25
account_fiscal_position_vat_check/models/partner.py
Normal file
25
account_fiscal_position_vat_check/models/partner.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2013-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# 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
|
||||
}
|
||||
}
|
||||
@@ -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 <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
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
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
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
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
|
||||
<record id="view_partner_property_form" model="ir.ui.view">
|
||||
<field name="name">customer.must.have.vat.fiscal_position_form</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="account.view_partner_property_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="property_account_position" position="attributes">
|
||||
<attribute name="on_change">fiscal_position_change(property_account_position, vat, customer)</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,13 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
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
|
||||
© 2013-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
|
||||
<record id="view_account_position_form" model="ir.ui.view">
|
||||
@@ -15,8 +12,9 @@
|
||||
<field name="model">account.fiscal.position</field>
|
||||
<field name="inherit_id" ref="account.view_account_position_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="country_group_id" position="after">
|
||||
<field name="customer_must_have_vat" />
|
||||
<field name="vat_required" position="attributes">
|
||||
<!-- always display that field -->
|
||||
<attribute name="attrs">{}</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
@@ -28,10 +26,10 @@
|
||||
<field name="inherit_id" ref="account.view_account_position_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="customer_must_have_vat" />
|
||||
<field name="vat_required" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user