Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tryton
Tryton
Commits
d5a5f27fad76
Commit
d5a5f27f
authored
Dec 26, 2022
by
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
Changes
8
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
modules/customs/CHANGELOG
View file @
d5a5f27f
* Support country organization for tariff code and duty rate
* Use ir.calendar.month for tariff code months
Version 6.6.0 - 2022-10-31
...
...
modules/customs/customs.py
View file @
d5a5f27f
...
...
@@ -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'
),
...
...
modules/customs/doc/index.rst
View file @
d5a5f27f
...
...
@@ -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*:
...
...
modules/customs/tests/test_module.py
View file @
d5a5f27f
...
...
@@ -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
()
...
...
modules/customs/view/duty_rate_form.xml
View file @
d5a5f27f
...
...
@@ -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"
/>
...
...
modules/customs/view/duty_rate_list.xml
View file @
d5a5f27f
...
...
@@ -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"
/>
...
...
modules/customs/view/tariff_code_form.xml
View file @
d5a5f27f
...
...
@@ -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"
/>
...
...
modules/customs/view/tariff_code_list.xml
View file @
d5a5f27f
...
...
@@ -4,5 +4,5 @@
<tree>
<field
name=
"code"
expand=
"1"
/>
<field
name=
"country"
expand=
"1"
/>
<
!-- TODO country group --
>
<
field
name=
"organization"
expand=
"1"
/
>
</tree>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment