Commit d5a5f27f authored by Cédric Krier's avatar Cédric Krier
Browse files

Support country organization for tariff code and duty rate

Closes #11838
parent 2bcaf38ad19a
Pipeline #61482 passed with stages
in 14 minutes and 31 seconds
* Support country organization for tariff code and duty rate
* Use ir.calendar.month for tariff code months
Version 6.6.0 - 2022-10-31
......
......@@ -14,7 +14,33 @@
from trytond.transaction import Transaction
class TariffCode(DeactivableMixin, ModelSQL, ModelView, MatchMixin):
class CountryMatchMixin(MatchMixin):
country = fields.Many2One(
'country.country', "Country",
states={
'invisible': Bool(Eval('organization')),
})
organization = fields.Many2One(
'country.organization', "Organization",
states={
'invisible': Bool(Eval('country')),
})
def match(self, pattern, match_none=False):
if 'country' in pattern:
pattern = pattern.copy()
country = pattern.pop('country')
if country is not None or match_none:
if self.country and self.country.id != country:
return False
if (self.organization
and country not in [
c.id for c in self.organization.countries]):
return False
return super().match(pattern, match_none=match_none)
class TariffCode(DeactivableMixin, CountryMatchMixin, ModelSQL, ModelView):
'Tariff Code'
__name__ = 'customs.tariff.code'
_rec_name = 'code'
......@@ -96,7 +122,7 @@
table_h.drop_column('_temp_start_month')
table_h.drop_column('_temp_end_month')
def match(self, pattern):
def match(self, pattern, match_none=False):
if 'date' in pattern:
pattern = pattern.copy()
date = pattern.pop('date')
......@@ -110,7 +136,7 @@
else:
if end <= date <= start:
return False
return super(TariffCode, self).match(pattern)
return super().match(pattern, match_none=match_none)
def get_duty_rate(self, pattern):
for rate in self.duty_rates:
......@@ -118,8 +144,8 @@
return rate
class DutyRate(ModelSQL, ModelView, MatchMixin):
class DutyRate(CountryMatchMixin, ModelSQL, ModelView):
'Duty Rate'
__name__ = 'customs.duty.rate'
tariff_code = fields.Many2One(
'customs.tariff.code', "Tariff Code", required=True)
......@@ -122,9 +148,7 @@
'Duty Rate'
__name__ = 'customs.duty.rate'
tariff_code = fields.Many2One(
'customs.tariff.code', "Tariff Code", required=True)
country = fields.Many2One('country.country', 'Country')
# TODO country group
type = fields.Selection([
('import', 'Import'),
('export', 'Export'),
......
......@@ -11,6 +11,7 @@
- The *Code* from the HS.
- The *Country* in case of a country specific code.
- The *Organization* in case of a country organization code.
- The *Start* / *End* period of the year for which the code is valid.
.. _`Harmonized System`: http://en.wikipedia.org/wiki/Harmonized_System
......@@ -22,6 +23,7 @@
- The *Tariff Code*.
- The *Country* for which the rate is.
- The *Organization* for which the rate is.
- The *Type*: *Import* or *Export*
- The *Start* and *End* date of validity.
- The *Computation Type*:
......
......@@ -13,8 +13,8 @@
module = 'customs'
@with_transaction()
def test_tariff_code_match(self):
'Test tariff code match'
def test_tariff_code_match_date(self):
"Test tariff code match date"
pool = Pool()
Tariff = pool.get('customs.tariff.code')
Template = pool.get('product.template')
......@@ -56,6 +56,58 @@
self.assertEqual(template.get_tariff_code(pattern), result)
@with_transaction()
def test_tariff_code_match_country(self):
"Test tariff code match country"
pool = Pool()
Tariff = pool.get('customs.tariff.code')
Country = pool.get('country.country')
country1 = Country(name="Country 1")
country1.save()
country2 = Country(name="Country 2")
country2.save()
tariff1 = Tariff(code='170390')
tariff1.save()
tariff2 = Tariff(code='17039099', country=country1)
tariff2.save()
self.assertTrue(tariff1.match({}))
self.assertTrue(tariff1.match({'country': None}))
self.assertTrue(tariff1.match({'country': country1.id}))
self.assertTrue(tariff2.match({}))
self.assertTrue(tariff2.match({'country': None}))
self.assertTrue(tariff2.match({'country': country1.id}))
self.assertFalse(tariff2.match({'country': country2.id}))
@with_transaction()
def test_tariff_code_match_country_organization(self):
"Test Tariff code match country with organization"
pool = Pool()
Tariff = pool.get('customs.tariff.code')
Country = pool.get('country.country')
Organization = pool.get('country.organization')
country1 = Country(name="Country 1")
country1.save()
country2 = Country(name="Country 2")
country2.save()
organization = Organization(
name="Organization", members=[{'country': country1.id}])
organization.save()
tariff1 = Tariff(code='170390')
tariff1.save()
tariff2 = Tariff(code='17039099', organization=organization)
tariff2.save()
self.assertTrue(tariff1.match({}))
self.assertTrue(tariff1.match({'country': None}))
self.assertTrue(tariff1.match({'country': country1.id}))
self.assertTrue(tariff2.match({}))
self.assertTrue(tariff2.match({'country': None}))
self.assertTrue(tariff2.match({'country': country1.id}))
self.assertFalse(tariff2.match({'country': country2.id}))
@with_transaction()
def test_get_tariff_code(self):
'Test get_tariff_code'
pool = Pool()
......
......@@ -6,5 +6,6 @@
<field name="tariff_code"/>
<label name="type"/>
<field name="type"/>
<label name="country"/>
<field name="country"/>
......@@ -9,7 +10,8 @@
<label name="country"/>
<field name="country"/>
<!-- TODO country group -->
<newline/>
<label name="organization"/>
<field name="organization"/>
<label name="start_date"/>
<field name="start_date"/>
<label name="end_date"/>
......
......@@ -4,7 +4,7 @@
<tree>
<field name="tariff_code" expand="1"/>
<field name="country" expand="1"/>
<!-- TODO country group -->
<field name="organization" expand="1"/>
<field name="type"/>
<field name="start_date"/>
<field name="end_date"/>
......
......@@ -8,5 +8,6 @@
<field name="active"/>
<label name="description"/>
<field name="description" colspan="3"/>
<label name="country"/>
<field name="country"/>
......@@ -11,7 +12,8 @@
<label name="country"/>
<field name="country"/>
<!-- TODO country group -->
<newline/>
<label name="organization"/>
<field name="organization"/>
<label id="from" string="From"/>
<group id="start" col="2">
<field name="start_day"/>
......
......@@ -4,5 +4,5 @@
<tree>
<field name="code" expand="1"/>
<field name="country" expand="1"/>
<!-- TODO country group -->
<field name="organization" expand="1"/>
</tree>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment