This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stock.py
84 lines (68 loc) · 2.7 KB
/
stock.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
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from functools import partial
from itertools import groupby
from trytond.model import fields
from trytond.pool import PoolMeta
from trytond.tools import sortable_values
from .common import parcel_weight
class ShipmentIn(metaclass=PoolMeta):
__name__ = 'stock.shipment.in'
def _group_parcel_key(self, lines, line):
"""
The key to group lines by parcel
"""
return ()
@fields.depends('carrier')
def _parcel_weight(self, parcel):
if self.carrier:
return parcel_weight(parcel, self.carrier.weight_uom)
@fields.depends('carrier', 'incoming_moves',
methods=['_group_parcel_key', '_parcel_weight'])
def _get_carrier_context(self):
context = super(ShipmentIn, self)._get_carrier_context()
if not self.carrier:
return context
if self.carrier.carrier_cost_method != 'weight':
return context
weights = []
context['weights'] = weights
lines = self.incoming_moves or []
keyfunc = partial(self._group_parcel_key, lines)
lines = sorted(lines, key=sortable_values(keyfunc))
for key, parcel in groupby(lines, key=keyfunc):
weights.append(self._parcel_weight(parcel))
return context
class ShipmentOut(metaclass=PoolMeta):
__name__ = 'stock.shipment.out'
def _group_parcel_key(self, lines, line):
"""
The key to group lines by parcel
"""
return ()
@fields.depends('carrier')
def _parcel_weight(self, parcel):
if self.carrier:
return parcel_weight(parcel, self.carrier.weight_uom)
@fields.depends(
'state', 'carrier', 'inventory_moves', 'outgoing_moves',
'warehouse_storage', 'warehouse_output',
methods=['_group_parcel_key', '_parcel_weight'])
def _get_carrier_context(self):
context = super(ShipmentOut, self)._get_carrier_context()
if not self.carrier:
return context
if self.carrier.carrier_cost_method != 'weight':
return context
weights = []
context['weights'] = weights
if (self.state in {'draft', 'waiting', 'assigned'}
and self.warehouse_storage != self.warehouse_output):
lines = self.inventory_moves or []
else:
lines = self.outgoing_moves or []
keyfunc = partial(self._group_parcel_key, lines)
lines = sorted(lines, key=sortable_values(keyfunc))
for key, parcel in groupby(lines, key=keyfunc):
weights.append(self._parcel_weight(parcel))
return context