mirror of
https://github.com/OCA/intrastat-extrastat.git
synced 2025-02-16 17:13:41 +02:00
intrastat_base: intrastat field is now a selection field
intrastat field on account.fiscal.position is now a selection field with 3 values : b2b/b2c/no Add views on account.fiscal.position.template
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
"views/res_config_settings.xml",
|
||||
"views/intrastat.xml",
|
||||
"views/account_fiscal_position.xml",
|
||||
"views/account_fiscal_position_template.xml",
|
||||
],
|
||||
"demo": ["demo/intrastat_demo.xml"],
|
||||
"installable": True,
|
||||
|
||||
@@ -2,13 +2,50 @@
|
||||
# @author: <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class AccountFiscalPosition(models.Model):
|
||||
_inherit = "account.fiscal.position"
|
||||
|
||||
intrastat = fields.Boolean(
|
||||
help="Set to True if the invoices with this fiscal position should "
|
||||
intrastat = fields.Selection(
|
||||
"_intrastat_selection",
|
||||
help="When set to B2B or B2C, the invoices with this fiscal position will "
|
||||
"be taken into account for the generation of the intrastat reports.",
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _intrastat_selection(self):
|
||||
return [
|
||||
("b2b", _("B2B")),
|
||||
("b2c", _("B2C")),
|
||||
("no", _("No")),
|
||||
]
|
||||
|
||||
@api.constrains("intrastat", "vat_required")
|
||||
def _check_intrastat(self):
|
||||
for position in self:
|
||||
if position.intrastat == "b2b" and not position.vat_required:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"The fiscal position '%s' has intrastat set to B2B, "
|
||||
"so the option 'VAT Required' must be enabled."
|
||||
)
|
||||
% position.display_name
|
||||
)
|
||||
elif position.intrastat == "b2c" and position.vat_required:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"The fiscal position '%s' has intrastat set to B2C, "
|
||||
"so the option 'VAT Required' mustn't be enabled."
|
||||
)
|
||||
% position.display_name
|
||||
)
|
||||
|
||||
@api.onchange("intrastat", "vat_required")
|
||||
def intrastat_change(self):
|
||||
if self.intrastat == "b2b" and not self.vat_required:
|
||||
self.vat_required = True
|
||||
elif self.intrastat == "b2c" and self.vat_required:
|
||||
self.vat_required = False
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
# Copyright 2020-2022 Akretion France (http://www.akretion.com/)
|
||||
# @author: <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class AccountFiscalPositionTemplate(models.Model):
|
||||
_inherit = "account.fiscal.position.template"
|
||||
|
||||
intrastat = fields.Boolean(
|
||||
help="Check this if you want to generate intrastat declarations with"
|
||||
"the created fiscal position",
|
||||
intrastat = fields.Selection(
|
||||
"_intrastat_selection",
|
||||
help="When set to B2B or B2C, the invoices with this fiscal position will "
|
||||
"be taken into account for the generation of the intrastat reports.",
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _intrastat_selection(self):
|
||||
return self.env["account.fiscal.position"]._intrastat_selection()
|
||||
|
||||
@@ -8,7 +8,7 @@ from odoo import fields, models
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
intrastat_fiscal_position = fields.Boolean(
|
||||
intrastat_fiscal_position = fields.Selection(
|
||||
related="fiscal_position_id.intrastat",
|
||||
store=True,
|
||||
string="Intrastat Fiscal Position",
|
||||
|
||||
@@ -28,3 +28,21 @@ class TestIntrastatBase(IntrastatCommon):
|
||||
def test_accessory(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
self.shipping_cost.type = "consu"
|
||||
|
||||
def test_fiscal_position(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
self.env["account.fiscal.position"].create(
|
||||
{
|
||||
"name": "TestB2B",
|
||||
"vat_required": False,
|
||||
"intrastat": "b2b",
|
||||
}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
self.env["account.fiscal.position"].create(
|
||||
{
|
||||
"name": "TestB2C",
|
||||
"vat_required": True,
|
||||
"intrastat": "b2c",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -32,11 +32,20 @@
|
||||
<field name="name" position="after">
|
||||
<filter
|
||||
name="intrastat"
|
||||
domain="[('intrastat', '=', True)]"
|
||||
domain="[('intrastat', 'in', ('b2b', 'b2c'))]"
|
||||
string="Intrastat"
|
||||
/>
|
||||
<separator />
|
||||
</field>
|
||||
<filter name="active" position="after">
|
||||
<group name="groupby">
|
||||
<filter
|
||||
name="intrastat_groupby"
|
||||
string="Intrastat"
|
||||
context="{'group_by': 'intrastat'}"
|
||||
/>
|
||||
</group>
|
||||
</filter>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
48
intrastat_base/views/account_fiscal_position_template.xml
Normal file
48
intrastat_base/views/account_fiscal_position_template.xml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!--
|
||||
Copyright 2023 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_template_form" model="ir.ui.view">
|
||||
<field name="name">intrastat.account.fiscal.position.form</field>
|
||||
<field name="model">account.fiscal.position.template</field>
|
||||
<field name="inherit_id" ref="account.view_account_position_template_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="vat_required" position="after">
|
||||
<field name="intrastat" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_account_position_template_tree" model="ir.ui.view">
|
||||
<field name="name">intrastat.account.fiscal.position.tree</field>
|
||||
<field name="model">account.fiscal.position.template</field>
|
||||
<field name="inherit_id" ref="account.view_account_position_template_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="intrastat" optional="show" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_account_position_template_search" model="ir.ui.view">
|
||||
<field name="model">account.fiscal.position.template</field>
|
||||
<field name="inherit_id" ref="account.view_account_position_template_search" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<filter
|
||||
name="intrastat"
|
||||
domain="[('intrastat', 'in', ('b2b', 'b2c'))]"
|
||||
string="Intrastat"
|
||||
/>
|
||||
<group name="groupby">
|
||||
<filter
|
||||
name="intrastat_groupby"
|
||||
string="Intrastat"
|
||||
context="{'group_by': 'intrastat'}"
|
||||
/>
|
||||
</group>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user