-
Notifications
You must be signed in to change notification settings - Fork 3
/
sale.py
82 lines (65 loc) · 2.38 KB
/
sale.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
# -*- coding: utf-8 -*-
"""
:copyright: (c) 2014 by Openlabs Technologies & Consulting (P) Limited
:license: BSD, see LICENSE for more details.
"""
from trytond.model import ModelView, ModelSQL, fields
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval
from incoterm import Incoterm
__all__ = ['Sale', 'SaleIncoterm']
__metaclass__ = PoolMeta
class Sale:
'Sale'
__name__ = 'sale.sale'
incoterms = fields.One2Many(
'sale.incoterm', 'sale', 'Sales Incoterm', states={
'readonly': Eval('state') != 'draft',
}, depends=['state', 'currency', 'total_amount'],
context={
'currency': Eval('currency'),
'value': Eval('total_amount'),
}
)
def create_invoice(self, invoice_type):
'''
Create and return an invoice of type invoice_type
'''
InvoiceIncoterm = Pool().get('account.invoice.incoterm')
invoice = super(Sale, self).create_invoice(invoice_type)
if invoice:
InvoiceIncoterm.create(map(
lambda incoterm: {
'year': incoterm.year,
'abbrevation': incoterm.abbrevation,
'value': incoterm.value,
'currency': incoterm.currency.id,
'city': incoterm.city,
'invoice': invoice.id,
}, self.incoterms
))
return invoice
def create_shipment(self, shipment_type):
'''
Create and return shipments of type shipment_type
'''
ShipmentIncoterm = Pool().get('stock.shipment.out.incoterm')
shipments = super(Sale, self).create_shipment(shipment_type)
if shipment_type != 'out':
return shipments
for shipment in shipments:
ShipmentIncoterm.create(map(
lambda incoterm: {
'year': incoterm.year,
'abbrevation': incoterm.abbrevation,
'value': incoterm.value,
'currency': incoterm.currency.id,
'city': incoterm.city,
'shipment_out': shipment.id,
}, self.incoterms
))
return shipments
class SaleIncoterm(Incoterm, ModelSQL, ModelView):
'Sale Incoterm'
__name__ = 'sale.incoterm'
sale = fields.Many2One('sale.sale', 'Sale', required=True)