Skip to content

Commit

Permalink
[MIG] l10n_be_intrastat_product: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdidderen-noviat committed Nov 12, 2023
1 parent 9f59e8b commit d2fa822
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions l10n_be_intrastat_product/models/intrastat_product_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,14 @@ class IntrastatProductDeclaration(models.Model):

def _get_region(self, inv_line, notedict):
region = super()._get_region(inv_line, notedict)
if self.company_country_code.upper() == "BE" and not region:
if self.company_country_code == "BE" and not region:
msg = _(
"The Intrastat Region of the Company is not set, "
"please configure it first."
)
self._account_config_warning(msg)
return region

def _get_vat(self, inv_line, notedict):
if self.company_country_code.upper() == "BE" and (
inv_line.move_id.fiscal_position_id.intrastat == "b2c"
or (
inv_line.move_id.fiscal_position_id.intrastat == "b2b"
and (
not inv_line.move_id.fiscal_position_id.vat_required
or (
inv_line.partner_id.vat
and inv_line.partner_id.vat.lower().strip() == "na"
)
)
)
):
return "QV999999999999"
else:
return super()._get_vat(inv_line, notedict)

def _handle_refund(self, inv_line, line_vals, notedict):
"""
NBB/BNB Intrastat Manual 2022 :
Expand All @@ -68,7 +50,7 @@ def _handle_refund(self, inv_line, line_vals, notedict):
Move the refund handling to the 'intrastat_product' module and
add refund unit tests.
"""
if self.company_country_code.upper() != "BE":
if self.company_country_code != "BE":
return
refund = inv_line.move_id
if refund.intrastat_transaction_id:
Expand Down Expand Up @@ -154,7 +136,7 @@ def _handle_refund(self, inv_line, line_vals, notedict):
def _update_computation_line_vals(self, inv_line, line_vals, notedict):
super()._update_computation_line_vals(inv_line, line_vals, notedict)
# handling of refunds
if self.company_country_code.upper() == "BE":
if self.company_country_code == "BE":
inv = inv_line.move_id
if inv.move_type in ["in_refund", "out_refund"]:
self._handle_refund(inv_line, line_vals, notedict)
Expand Down Expand Up @@ -189,7 +171,7 @@ def _handle_invoice_accessory_cost(
stated on a separate line on the invoice), transport and insurance
costs may not be included in the value of the goods.
"""
if self.company_country_code.upper() != "BE":
if self.company_country_code != "BE":
return super()._handle_invoice_accessory_cost(
invoice,
lines_current_invoice,
Expand All @@ -201,7 +183,7 @@ def _handle_invoice_accessory_cost(
return

def _gather_invoices_init(self, notedict):
if self.company_country_code.upper() == "BE":
if self.company_country_code == "BE":
# Special commodity codes
# Current version implements only regular credit notes
special_code = "99600000"
Expand Down Expand Up @@ -238,7 +220,7 @@ def _sanitize_vat(self, vat):
def _check_generate_xml(self):
self.ensure_one()
res = super()._check_generate_xml()
if self.company_country_code.upper() == "BE":
if self.company_country_code == "BE":
if not self.declaration_line_ids:
res = self.generate_declaration()
return res
Expand Down Expand Up @@ -339,7 +321,7 @@ def _node_Report(self, parent, decl_code):

def _generate_xml(self):
self.ensure_one()
if self.company_country_code.upper() == "BE":
if self.company_country_code == "BE":
if self.declaration_type == "arrivals":
decl_code = "19"
if self.reporting_level == "standard":
Expand Down Expand Up @@ -374,14 +356,14 @@ def _generate_xml(self):

def _xls_computation_line_fields(self):
res = super()._xls_computation_line_fields()
if self.company_country_code.upper() == "BE":
if self.company_country_code == "BE":
i = res.index("product_origin_country")
res.pop(i)
return res

def _xls_declaration_line_fields(self):
res = super()._xls_declaration_line_fields()
if self.company_country_code.upper() == "BE":
if self.company_country_code == "BE":
if self.declaration_type == "dispatches":
i = res.index("hs_code")
res.insert(i + 1, "product_origin_country")
Expand All @@ -392,6 +374,27 @@ class IntrastatProductComputationLine(models.Model):
_inherit = "intrastat.product.computation.line"
_description = "Intrastat Product Computation Lines for Belgium"

@api.depends("partner_id")
def _compute_vat(self):
for rec in self:
if rec.company_country_code == "BE" and (
rec.invoice_id.fiscal_position_id.intrastat == "b2c"
or (
rec.invoice_id.fiscal_position_id.intrastat == "b2b"
and (
not rec.invoice_id.fiscal_position_id.vat_required
or (
rec.partner_id.vat
and rec.partner_id.vat.lower().strip() == "na"
)
)
)
):
rec.vat = "QV999999999999"
else:
super(IntrastatProductComputationLine, rec)._compute_vat()
return

@api.constrains("vat")
def _check_vat(self):
for rec in self:
Expand All @@ -401,7 +404,7 @@ def _check_vat(self):

def _group_line_hashcode_fields(self):
res = super()._group_line_hashcode_fields()
if self.company_country_code.upper() == "BE":
if self.company_country_code == "BE":
if self.declaration_type == "arrivals":
del res["product_origin_country"]
del res["vat"]
Expand Down

0 comments on commit d2fa822

Please sign in to comment.