Files
tryton/sale.py
T

40 lines
1.1 KiB
Python
Raw Normal View History

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-02-07 19:50:26 +01:00
from functools import partial
from itertools import groupby
from trytond.pool import PoolMeta
from .common import parcel_weight
2012-09-24 22:17:49 +02:00
__all__ = ['Sale']
2012-02-07 19:50:26 +01:00
2012-04-03 20:06:53 +02:00
2012-09-24 22:17:49 +02:00
class Sale:
2016-03-11 21:01:53 +01:00
__metaclass__ = PoolMeta
2012-09-24 22:17:49 +02:00
__name__ = 'sale.sale'
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(Sale, self)._get_carrier_context()
2012-02-07 19:50:26 +01:00
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.lines 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):
weights.append(parcel_weight(
parcel, self.carrier.weight_uom, 'unit'))
2012-02-07 19:50:26 +01:00
return context