Files
tryton/sale.py
T
Cédric Krier 5bf8f01390 Add carrier_carriage module
issue11623
review443451003
2022-09-10 17:35:38 +02:00

28 lines
956 B
Python

# 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 decimal import Decimal
from trytond.pool import PoolMeta
class Sale(metaclass=PoolMeta):
__name__ = 'sale.sale'
def _get_carrier_context(self, carrier):
context = super()._get_carrier_context(carrier)
if carrier.carrier_cost_method != 'percentage':
return context
if not self.currency:
return context
context = context.copy()
amount = 0
for line in self.lines or []:
if (getattr(line, 'unit_price', None)
and (getattr(line, 'quantity') or 0) > 0
and not getattr(line, 'shipment_cost', None)):
amount += line.unit_price * Decimal(str(line.quantity))
context['amount'] = amount
context['currency'] = self.currency.id
return context