Skip to content

Commit

Permalink
[14.0][l10n_it_intrastat_statement] Check if the out_refund or in_ref…
Browse files Browse the repository at this point in the history
…und can be compensated in the same period
  • Loading branch information
robyf70 committed Jan 25, 2024
1 parent 2ec01ab commit 522d0d0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
26 changes: 19 additions & 7 deletions l10n_it_intrastat_statement/models/intrastat_statement.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2019 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from datetime import date, datetime, timedelta
from datetime import date, timedelta

from dateutil.relativedelta import relativedelta

Expand Down Expand Up @@ -449,7 +449,7 @@ def get_dates_start_stop(self):
month = self.period_number
period_date_start = date(year, month, 1)
period_date_stop = (
datetime(year, month, 1) + relativedelta(months=1) - timedelta(days=1)
period_date_start + relativedelta(months=1) - timedelta(days=1)
)
elif self.period_type == "T":
quarter = self.period_number
Expand Down Expand Up @@ -819,11 +819,23 @@ def compute_statement(self):
refund_section_details = (section_type, refund_section_number)
section_field = self.get_section_field_name(*section_details)
for line in self[section_field]:
refund_section_model = self.get_section_model(
*refund_section_details
)
to_refund_model = self.env[refund_section_model]
self.refund_line(line, to_refund_model)
# Compensation can happen only if the credit note has been issued
# for invoices belonging the considered period. Here we check
# if the reversed entry of the Sale/Purchase section 2 line
# respect this constraint otherwise no compensation shouldn't
# happen
if (
line.invoice_id.reversed_entry_id
and line.invoice_id.reversed_entry_id.invoice_date
>= period_date_start
and line.invoice_id.reversed_entry_id.invoice_date
<= period_date_stop
):
refund_section_model = self.get_section_model(
*refund_section_details
)
to_refund_model = self.env[refund_section_model]
self.refund_line(line, to_refund_model)
return True

@staticmethod
Expand Down
39 changes: 20 additions & 19 deletions l10n_it_intrastat_statement/views/intrastat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@
<field name="model">account.intrastat.statement.sale.section1</field>
<field name="arch" type="xml">
<tree>
<field name="sequence" />
<field name="invoice_id" />
<field name="partner_id" string="Buyer" />
<field name="country_partner_id" string="Buyer State" />
<field name="intrastat_code_id" string="Goods Code" />
<field name="weight_kg" />
<field name="country_destination_id" />
<field name="province_origin_id" />
<field name="amount_euro" sum="Total" />
<field name="sequence" />
<field name="invoice_id" />
<field name="partner_id" string="Buyer" />
<field name="country_partner_id" string="Buyer State" />
<field name="intrastat_code_id" string="Goods Code" />
<field name="weight_kg" />
<field name="country_destination_id" />
<field name="province_origin_id" />
<field name="amount_euro" sum="Total" />
</tree>
</field>
</record>
Expand Down Expand Up @@ -356,16 +356,17 @@
<field name="model">account.intrastat.statement.sale.section2</field>
<field name="arch" type="xml">
<tree>
<field name="sequence" />
<field name="year_id" />
<field name="quarterly" />
<field name="month" />
<field name="country_partner_id" string="Buyer State" />
<field name="partner_id" string="Buyer" />
<field name="vat_code" string="Buyer VAT Code" />
<field name="intrastat_code_id" string="Goods Code" />
<field name="sign_variation" />
<field name="amount_euro" sum="Total" />
<field name="sequence" />
<field name="invoice_id" />
<field name="year_id" />
<field name="quarterly" />
<field name="month" />
<field name="country_partner_id" string="Buyer State" />
<field name="partner_id" string="Buyer" />
<field name="vat_code" string="Buyer VAT Code" />
<field name="intrastat_code_id" string="Goods Code" />
<field name="sign_variation" />
<field name="amount_euro" sum="Total" />
</tree>
</field>
</record>
Expand Down

0 comments on commit 522d0d0

Please sign in to comment.