Skip to content

Commit

Permalink
[14.0][IMP] add ability to set intrastat only for in_ or out_ invoice…
Browse files Browse the repository at this point in the history
…s in l10n_it_intrastat
  • Loading branch information
sergiocorato committed Jul 10, 2024
1 parent 55e4c1c commit fe86928
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
2 changes: 1 addition & 1 deletion l10n_it_intrastat/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down
33 changes: 33 additions & 0 deletions l10n_it_intrastat/migrations/14.0.1.4.3/pre-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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;
""",
)
26 changes: 18 additions & 8 deletions l10n_it_intrastat/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
16 changes: 14 additions & 2 deletions l10n_it_intrastat/tests/test_intrastat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
3 changes: 2 additions & 1 deletion l10n_it_intrastat/views/account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<xpath expr="//field[@name='note']" position="before">
<separator string="Intrastat" />
<group colspan="4">
<field name="intrastat" />
<field name="intrastat_purchase" />
<field name="intrastat_sale" />
</group>
</xpath>
</field>
Expand Down

0 comments on commit fe86928

Please sign in to comment.