2014-12-02 12:55:11 +01:00
|
|
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
# this repository contains the full copyright notices and license terms.
|
2012-09-24 22:17:49 +02:00
|
|
|
from itertools import groupby
|
2012-02-07 19:50:26 +01:00
|
|
|
from functools import partial
|
|
|
|
|
|
2017-02-14 23:38:51 +01:00
|
|
|
from trytond.pool import PoolMeta
|
|
|
|
|
|
|
|
|
|
from .common import parcel_weight
|
2012-09-24 22:17:49 +02:00
|
|
|
|
|
|
|
|
__all__ = ['ShipmentIn', 'ShipmentOut']
|
2012-02-07 19:50:26 +01:00
|
|
|
|
|
|
|
|
|
2012-09-24 22:17:49 +02:00
|
|
|
class ShipmentIn:
|
2016-03-11 21:01:53 +01:00
|
|
|
__metaclass__ = PoolMeta
|
2012-09-24 22:17:49 +02:00
|
|
|
__name__ = 'stock.shipment.in'
|
2012-02-07 19:50:26 +01:00
|
|
|
|
|
|
|
|
def _group_parcel_key(self, lines, line):
|
|
|
|
|
"""
|
|
|
|
|
The key to group lines by parcel
|
|
|
|
|
"""
|
|
|
|
|
return None
|
|
|
|
|
|
2012-09-24 22:17:49 +02:00
|
|
|
def _get_carrier_context(self):
|
|
|
|
|
context = super(ShipmentIn, self)._get_carrier_context()
|
|
|
|
|
if not self.carrier:
|
2012-02-07 19:50:26 +01:00
|
|
|
return context
|
2012-09-24 22:17:49 +02:00
|
|
|
if self.carrier.carrier_cost_method != 'weight':
|
2012-02-07 19:50:26 +01:00
|
|
|
return context
|
|
|
|
|
context = context.copy()
|
|
|
|
|
weights = []
|
|
|
|
|
context['weights'] = weights
|
|
|
|
|
|
2012-09-24 22:17:49 +02:00
|
|
|
lines = self.incoming_moves or []
|
2012-02-07 19:50:26 +01:00
|
|
|
keyfunc = partial(self._group_parcel_key, lines)
|
|
|
|
|
lines = sorted(lines, key=keyfunc)
|
|
|
|
|
|
|
|
|
|
for key, parcel in groupby(lines, key=keyfunc):
|
2017-02-14 23:38:51 +01:00
|
|
|
weights.append(parcel_weight(parcel, self.carrier.weight_uom))
|
2012-02-07 19:50:26 +01:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
2012-09-24 22:17:49 +02:00
|
|
|
class ShipmentOut:
|
2016-03-11 21:01:53 +01:00
|
|
|
__metaclass__ = PoolMeta
|
2012-09-24 22:17:49 +02:00
|
|
|
__name__ = 'stock.shipment.out'
|
2012-02-07 19:50:26 +01:00
|
|
|
|
|
|
|
|
def _group_parcel_key(self, lines, line):
|
|
|
|
|
"""
|
|
|
|
|
The key to group lines by parcel
|
|
|
|
|
"""
|
|
|
|
|
return None
|
|
|
|
|
|
2012-09-24 22:17:49 +02:00
|
|
|
def _get_carrier_context(self):
|
|
|
|
|
context = super(ShipmentOut, self)._get_carrier_context()
|
|
|
|
|
if not self.carrier:
|
2012-02-07 19:50:26 +01:00
|
|
|
return context
|
2012-09-24 22:17:49 +02:00
|
|
|
if self.carrier.carrier_cost_method != 'weight':
|
2012-02-07 19:50:26 +01:00
|
|
|
return context
|
|
|
|
|
context = context.copy()
|
|
|
|
|
weights = []
|
|
|
|
|
context['weights'] = weights
|
|
|
|
|
|
2012-09-24 22:17:49 +02:00
|
|
|
lines = self.inventory_moves or []
|
2012-02-07 19:50:26 +01:00
|
|
|
keyfunc = partial(self._group_parcel_key, lines)
|
|
|
|
|
lines = sorted(lines, key=keyfunc)
|
|
|
|
|
|
|
|
|
|
for key, parcel in groupby(lines, key=keyfunc):
|
2017-02-14 23:38:51 +01:00
|
|
|
weights.append(parcel_weight(parcel, self.carrier.weight_uom))
|
2012-02-07 19:50:26 +01:00
|
|
|
return context
|