-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[14.0]intrastat - improved brexit support
- Loading branch information
1 parent
a8cdd74
commit 2874b76
Showing
9 changed files
with
240 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright 2022 Noviat. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import UserError | ||
|
||
XI_COUNTY_NAMES = [ | ||
"antrim", | ||
"armagh", | ||
"down", | ||
"fermanagh", | ||
"londonderry", | ||
"tyrone", | ||
"northern ireland", | ||
] | ||
|
||
XI_COUNTIES = [ | ||
"base.state_uk18", # County Antrim | ||
"base.state_uk19", # County Armagh | ||
"base.state_uk20", # County Down | ||
"base.state_uk22", # County Fermanagh | ||
"base.state_uk23", # County Londonderry | ||
"base.state_uk24", # County Tyrone | ||
"base.state_ie_27", # Antrim | ||
"base.state_ie_28", # Armagh | ||
"base.state_ie_29", # Down | ||
"base.state_ie_30", # Fermanagh | ||
"base.state_ie_31", # Londonderry | ||
"base.state_ie_32", # Tyrone | ||
] | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
@api.model | ||
def _get_xi_counties(self): | ||
return [self.env.ref(x) for x in XI_COUNTIES] | ||
|
||
@api.model | ||
def _get_xu_counties(self): | ||
uk_counties = self.env.ref("base.uk").state_ids | ||
xu_counties = uk_counties.filtered(lambda r: r not in self._get_xi_counties()) | ||
return xu_counties | ||
|
||
def _get_intrastat_country_code(self, country=None, state=None): | ||
if self: | ||
self.ensure_one() | ||
country = self.country_id | ||
state = self.state_id | ||
else: | ||
state = state or self.env["res.country.state"] | ||
country = country or state.country_id | ||
if not country: | ||
raise UserError( | ||
_("Programming Error when calling '_get_intrastat_country_code()") | ||
) | ||
cc = country.code | ||
if cc == "GB": | ||
cc = "XU" | ||
if state and cc in ["XU", "IE"]: | ||
if ( | ||
state in self._get_xi_counties() | ||
or state.name.lower().strip() in XI_COUNTY_NAMES | ||
): | ||
cc = "XI" | ||
return cc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Copyright 2022 Noviat. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.tests import Form, SavepointCase | ||
|
||
from .common import IntrastatProductCommon | ||
|
||
|
||
class TestIntrastatBrexit(IntrastatProductCommon, SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.inv_obj = cls.env["account.move"] | ||
cls.hs_code_whiskey = cls.env["hs.code"].create( | ||
{ | ||
"description": "Whiskey", | ||
"local_code": "22083000", | ||
} | ||
) | ||
cls.product_xi = cls.env["product.product"].create( | ||
{ | ||
"name": "Bushmills Original", | ||
"weight": 1.4, | ||
"list_price": 30.0, | ||
"standard_price": 15.0, | ||
"origin_country_id": cls.env.ref("base.uk").id, | ||
"origin_state_id": cls.env.ref("base.state_uk18").id, | ||
"hs_code_id": cls.hs_code_whiskey.id, | ||
} | ||
) | ||
cls.product_xu = cls.env["product.product"].create( | ||
{ | ||
"name": "Glenfiddich", | ||
"weight": 1.4, | ||
"list_price": 50.0, | ||
"standard_price": 25.0, | ||
"origin_country_id": cls.env.ref("base.uk").id, | ||
"origin_state_id": cls.env.ref("base.state_uk6").id, | ||
"hs_code_id": cls.hs_code_whiskey.id, | ||
} | ||
) | ||
cls.partner_xi = cls.env["res.partner"].create( | ||
{ | ||
"name": "Bushmills Distillery", | ||
"country_id": cls.env.ref("base.uk").id, | ||
"state_id": cls.env.ref("base.state_uk18").id, | ||
"vat": "XI123456782", | ||
"property_account_position_id": cls.position.id, | ||
} | ||
) | ||
|
||
def test_brexit_sale(self): | ||
inv_out_xi = self.inv_obj.with_context(default_move_type="out_invoice").create( | ||
{ | ||
"partner_id": self.partner_xi.id, | ||
"fiscal_position_id": self.position.id, | ||
} | ||
) | ||
with Form(inv_out_xi) as inv_form: | ||
with inv_form.invoice_line_ids.new() as ail: | ||
ail.product_id = self.product_c3po.product_variant_ids[0] | ||
inv_out_xi.action_post() | ||
|
||
self._create_declaration( | ||
{ | ||
"declaration_type": "dispatches", | ||
"year": str(inv_out_xi.date.year), | ||
"month": str(inv_out_xi.date.month).zfill(2), | ||
} | ||
) | ||
self.declaration.action_gather() | ||
self.declaration.generate_declaration() | ||
cline = self.declaration.computation_line_ids | ||
dline = self.declaration.declaration_line_ids | ||
self.assertEqual(cline.src_dest_country_code, "XI") | ||
self.assertEqual(dline.src_dest_country_code, "XI") | ||
|
||
def test_brexit_purchase(self): | ||
inv_in_xi = self.inv_obj.with_context(default_move_type="in_invoice").create( | ||
{ | ||
"partner_id": self.partner_xi.id, | ||
"fiscal_position_id": self.position.id, | ||
} | ||
) | ||
with Form(inv_in_xi) as inv_form: | ||
with inv_form.invoice_line_ids.new() as ail: | ||
ail.product_id = self.product_xi | ||
with inv_form.invoice_line_ids.new() as ail: | ||
ail.product_id = self.product_xu | ||
inv_in_xi.invoice_date = inv_in_xi.date | ||
inv_in_xi.action_post() | ||
|
||
self._create_declaration( | ||
{ | ||
"declaration_type": "arrivals", | ||
"year": str(inv_in_xi.date.year), | ||
"month": str(inv_in_xi.date.month).zfill(2), | ||
} | ||
) | ||
self.declaration.action_gather() | ||
self.declaration.generate_declaration() | ||
clines = self.declaration.computation_line_ids | ||
cl_xi = clines.filtered(lambda r: r.product_id == self.product_xi) | ||
cl_xu = clines.filtered(lambda r: r.product_id == self.product_xu) | ||
dlines = self.declaration.declaration_line_ids | ||
dl_xi = dlines.filtered(lambda r: r.computation_line_ids == cl_xi) | ||
dl_xu = dlines.filtered(lambda r: r.computation_line_ids == cl_xu) | ||
self.assertEqual(cl_xi.product_origin_country_code, "XI") | ||
self.assertEqual(cl_xu.product_origin_country_code, "XU") | ||
self.assertEqual(dl_xi.product_origin_country_code, "XI") | ||
self.assertEqual(dl_xu.product_origin_country_code, "XU") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.