-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathincoterm.py
84 lines (71 loc) · 2.38 KB
/
incoterm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
"""
incoterm
:copyright: (c) 2014 by Openlabs Technologies & Consulting (P) Limited
:license: BSD, see LICENSE for more details.
"""
from trytond.pool import Pool
from trytond.model import fields
from trytond.pyson import Eval
from trytond.transaction import Transaction
__all__ = ['Incoterm']
YEARS = [
('2000', '2000'),
('2010', '2010'),
]
ABBREVATIONS = [
(None, ''),
('EXW', 'EXW - Ex Works'),
('CPT', 'CPT - Carriage Paid To'),
('CIP', 'CIP - Carrier and Insurance Paid to'),
('DAT', 'DAT - Delivered at Terminal'),
('DAP', 'DAP - Delivered at Place'),
('DDP', 'DDP - Delivered Duty Paid'),
('FAS', 'FAS - Free Alongside Ship'),
('FCA', 'FCA - Free Carrier'),
('FOB', 'FOB - Free on Board'),
('CFR', 'CFR - Cost and Freight'),
('CIF', 'CIF - Cost, Insurance and Freight'),
('DAF', 'DAF - Delivered at Frontier'),
('DES', 'DES - Delivered Ex Ship'),
('DEQ', 'DEQ - Delievered Ex Quay'),
('DDU', 'DDU - Delivered Duty Unpaid'),
]
class Incoterm(object):
'Incoterm Mixin'
year = fields.Selection(YEARS, 'Year', select=True, required=True)
abbrevation = fields.Selection(
ABBREVATIONS, 'Abbrevation', select=True, required=True
)
value = fields.Numeric(
'Value', digits=(16, Eval('currency_digits', 2)),
depends=['currency_digits']
)
currency = fields.Many2One('currency.currency', 'Currency')
city = fields.Char('City', required=True)
currency_digits = fields.Function(
fields.Integer('Value', on_change_with=['currency'],
depends=['currency']
), 'on_change_with_currency'
)
def get_rec_name(self, name):
return "%s -(Incoterm %s)" % (self.abbrevation, self.year)
@staticmethod
def default_year():
return '2010'
@staticmethod
def default_currency():
Company = Pool().get('company.company')
if 'currency' in Transaction().context:
return Transaction().context.get('currency')
company_id = Transaction().context.get('company')
if company_id:
return Company(company_id).currency.id
return None
def on_change_with_currency(self, name=None):
if self.currency:
return self.currency.digits
return 2
@staticmethod
def default_value():
return Transaction().context.get('value')