Skip to content

Commit

Permalink
Merge PR #300 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by alexis-via
  • Loading branch information
OCA-git-bot committed Feb 17, 2025
2 parents dfe5358 + 44d8e7e commit 8b4232b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions intrastat_product/models/intrastat_product_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def default_get(self, fields_list):
)
declaration_type = fields.Selection(
selection="_get_declaration_type",
compute="_compute_declaration_type",
store=True,
precompute=True,
string="Type",
required=True,
tracking=True,
Expand Down Expand Up @@ -189,6 +192,45 @@ def _compute_year_month(self):
if this.year and this.month:
this.year_month = "-".join([this.year, this.month])

@api.depends("company_id", "year", "month")
def _compute_declaration_type(self):
for this in self:
company = this.company_id
declaration_type = False
if company:
if (
company.intrastat_arrivals == "exempt"
and company.intrastat_dispatches != "exempt"
):
declaration_type = "dispatches"
elif (
company.intrastat_dispatches == "exempt"
and company.intrastat_arrivals != "exempt"
):
declaration_type = "arrivals"
elif (
company.intrastat_dispatches != "exempt"
and company.intrastat_arrivals != "exempt"
and this.year
and this.month
):
existing_decls = self.search(
[
("year", "=", this.year),
("month", "=", this.month),
("company_id", "=", company.id),
]
)
if len(existing_decls) == 1:
declaration_type = (
existing_decls.declaration_type == "arrivals"
and "dispatches"
or "arrivals"
)
elif not existing_decls:
declaration_type = "dispatches"
this.declaration_type = declaration_type

@api.constrains("company_id")
def _check_company_country(self):
for this in self:
Expand Down

0 comments on commit 8b4232b

Please sign in to comment.