diff --git a/l10n_it_intrastat/__manifest__.py b/l10n_it_intrastat/__manifest__.py index 96033eee518b..2a4ce62fba5b 100644 --- a/l10n_it_intrastat/__manifest__.py +++ b/l10n_it_intrastat/__manifest__.py @@ -4,7 +4,7 @@ { "name": "ITA - Intrastat", - "version": "14.0.1.4.2", + "version": "14.0.1.4.3", "category": "Account", "summary": "Riclassificazione merci e servizi per dichiarazioni Intrastat", "author": "Openforce, Link IT srl, Agile Business Group, " diff --git a/l10n_it_intrastat/migrations/14.0.1.4.3/pre-migrate.py b/l10n_it_intrastat/migrations/14.0.1.4.3/pre-migrate.py new file mode 100644 index 000000000000..68c52d348a04 --- /dev/null +++ b/l10n_it_intrastat/migrations/14.0.1.4.3/pre-migrate.py @@ -0,0 +1,34 @@ + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + for table, column in [ + ("account_fiscal_position", "intrastat_sale"), + ("account_fiscal_position", "intrastat_purchase"), + ]: + if not openupgrade.column_exists(env.cr, table, column): + openupgrade.add_fields( + env, + [ + ( + column, + ".".join(table.split("_")), + False, + "boolean", + False, + "l10n_it_intrastat", + ) + ], + ) + openupgrade.logged_query( + env.cr, + """ +UPDATE account_fiscal_position +SET + intrastat_sale = intrastat, + intrastat_purchase = intrastat +WHERE intrastat is true; + """, + ) diff --git a/l10n_it_intrastat/models/account.py b/l10n_it_intrastat/models/account.py index 8b25c7cebf21..868fb9792310 100644 --- a/l10n_it_intrastat/models/account.py +++ b/l10n_it_intrastat/models/account.py @@ -9,7 +9,8 @@ class AccountFiscalPosition(models.Model): _inherit = "account.fiscal.position" - intrastat = fields.Boolean(string="Subject to Intrastat") + intrastat_purchase = fields.Boolean(string="Subject to Intrastat (purchases)") + intrastat_sale = fields.Boolean(string="Subject to Intrastat (sales)") class AccountMoveLine(models.Model): @@ -299,7 +300,12 @@ class AccountMove(models.Model): @api.onchange("fiscal_position_id") def change_fiscal_position(self): - self.intrastat = self.fiscal_position_id.intrastat + self.intrastat = ( + self.move_type.startswith("out_") + and self.fiscal_position_id.intrastat_sale + or self.move_type.startswith("in_") + and self.fiscal_position_id.intrastat_purchase + ) @api.onchange("partner_id") def _onchange_partner_id(self): @@ -310,13 +316,17 @@ def _onchange_partner_id(self): @api.model_create_multi def create(self, vals_list): for val in vals_list: - if "intrastat" not in val and "fiscal_position_id" in val: - intrastat = ( - self.env["account.fiscal.position"] - .browse(val["fiscal_position_id"]) - .intrastat + if "fiscal_position_id" in val: + fiscal_position_id = self.env["account.fiscal.position"].browse( + val["fiscal_position_id"] ) - val.update({"intrastat": intrastat}) + if "intrastat" not in val: + intrastat = False + if val.get("move_type").startswith("out_"): + intrastat = fiscal_position_id.intrastat_sale + elif val.get("move_type").startswith("in_"): + intrastat = fiscal_position_id.intrastat_purchase + val.update({"intrastat": intrastat}) return super().create(vals_list) def action_post(self): diff --git a/l10n_it_intrastat/tests/test_intrastat.py b/l10n_it_intrastat/tests/test_intrastat.py index 763d3719e1cd..41b41ede3d6b 100644 --- a/l10n_it_intrastat/tests/test_intrastat.py +++ b/l10n_it_intrastat/tests/test_intrastat.py @@ -65,11 +65,12 @@ def test_invoice_totals(self): ) self.assertEqual(total_intrastat_amount, invoice.amount_untaxed) - def test_invoice_fiscal_postion(self): + def test_invoice_fiscal_position(self): self.partner01.property_account_position_id = self.fp_model.create( { "name": "F.P subjected to intrastat", - "intrastat": True, + "intrastat_sale": True, + "intrastat_purchase": False, } ) invoice = self.init_invoice( @@ -82,3 +83,14 @@ def test_invoice_fiscal_postion(self): invoice.action_post() invoice.compute_intrastat_lines() self.assertEqual(invoice.intrastat, True) + + invoice_purchase = self.init_invoice( + "in_invoice", + partner=self.partner01, + products=self.product01, + taxes=self.tax22, + ) + # Compute intrastat lines + invoice_purchase.action_post() + invoice_purchase.compute_intrastat_lines() + self.assertEqual(invoice_purchase.intrastat, False) diff --git a/l10n_it_intrastat/views/account.xml b/l10n_it_intrastat/views/account.xml index fb58f0e6f838..c4b737c41fc0 100644 --- a/l10n_it_intrastat/views/account.xml +++ b/l10n_it_intrastat/views/account.xml @@ -11,7 +11,8 @@ - + +