mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
account_fiscal_position_vat_check: black, isort and others
This commit is contained in:
@@ -3,16 +3,16 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Account Fiscal Position VAT Check',
|
||||
'version': '14.0.1.0.0',
|
||||
'category': 'Invoices & Payments',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Check VAT on invoice validation',
|
||||
'author': "Akretion,Odoo Community Association (OCA)",
|
||||
'website': 'https://github.com/OCA/account-financial-tools',
|
||||
'depends': ['account', 'base_vat'],
|
||||
'data': [
|
||||
'views/account_fiscal_position.xml',
|
||||
"name": "Account Fiscal Position VAT Check",
|
||||
"version": "14.0.1.0.0",
|
||||
"category": "Invoices & Payments",
|
||||
"license": "AGPL-3",
|
||||
"summary": "Check VAT on invoice validation",
|
||||
"author": "Akretion,Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/account-financial-tools",
|
||||
"depends": ["account", "base_vat"],
|
||||
"data": [
|
||||
"views/account_fiscal_position.xml",
|
||||
],
|
||||
'installable': True,
|
||||
"installable": True,
|
||||
}
|
||||
|
||||
@@ -2,27 +2,33 @@
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, _
|
||||
from odoo import _, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = 'account.move'
|
||||
_inherit = "account.move"
|
||||
|
||||
def _post(self, soft=True):
|
||||
"""Check that the customer has VAT set if required by the
|
||||
fiscal position"""
|
||||
for move in self:
|
||||
if (
|
||||
move.move_type in ('out_invoice', 'out_refund') and
|
||||
move.fiscal_position_id.vat_required and
|
||||
not move.commercial_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.") % (
|
||||
move.move_type in ("out_invoice", "out_refund")
|
||||
and move.fiscal_position_id.vat_required
|
||||
and not move.commercial_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."
|
||||
)
|
||||
% (
|
||||
move.fiscal_position_id.display_name,
|
||||
move.commercial_partner_id.display_name))
|
||||
move.commercial_partner_id.display_name,
|
||||
)
|
||||
)
|
||||
return super()._post(soft=soft)
|
||||
|
||||
@@ -2,25 +2,27 @@
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models, _
|
||||
from odoo import _, api, models
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
_inherit = "res.partner"
|
||||
|
||||
@api.onchange('property_account_position_id')
|
||||
@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 not self.vat:
|
||||
return {
|
||||
'warning': {
|
||||
'title': _('Missing VAT number:'),
|
||||
'message': _(
|
||||
"warning": {
|
||||
"title": _("Missing VAT number:"),
|
||||
"message": _(
|
||||
"You have set the fiscal position '%s' "
|
||||
"that require customers to have a VAT number. "
|
||||
"If you plan to use this partner as a customer, you "
|
||||
"should add its VAT number.") % fp.display_name
|
||||
"should add its VAT number."
|
||||
)
|
||||
% fp.display_name,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!--
|
||||
Copyright 2013-2020 Akretion France (https://akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
|
||||
<record id="view_account_position_form" model="ir.ui.view">
|
||||
<field name="name">customer.must.have.vat.fiscal_position_form</field>
|
||||
<field name="model">account.fiscal.position</field>
|
||||
<field name="inherit_id" ref="account.view_account_position_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="vat_required" position="attributes">
|
||||
<!-- always display that field -->
|
||||
<attribute name="attrs">{}</attribute>
|
||||
<record id="view_account_position_form" model="ir.ui.view">
|
||||
<field name="name">customer.must.have.vat.fiscal_position_form</field>
|
||||
<field name="model">account.fiscal.position</field>
|
||||
<field name="inherit_id" ref="account.view_account_position_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="vat_required" position="attributes">
|
||||
<!-- always display that field -->
|
||||
<attribute name="attrs">{}</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_account_position_tree" model="ir.ui.view">
|
||||
<field name="name">customer.must.have.vat.fiscal_position_tree</field>
|
||||
<field name="model">account.fiscal.position</field>
|
||||
<field name="inherit_id" ref="account.view_account_position_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="vat_required" />
|
||||
</record>
|
||||
<record id="view_account_position_tree" model="ir.ui.view">
|
||||
<field name="name">customer.must.have.vat.fiscal_position_tree</field>
|
||||
<field name="model">account.fiscal.position</field>
|
||||
<field name="inherit_id" ref="account.view_account_position_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="vat_required" />
|
||||
</field>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
../../../../account_fiscal_position_vat_check
|
||||
6
setup/account_fiscal_position_vat_check/setup.py
Normal file
6
setup/account_fiscal_position_vat_check/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
Reference in New Issue
Block a user