trytond-carrier_zip/sale.py

30 lines
1.1 KiB
Python
Raw Normal View History

2014-04-11 15:45:11 +02:00
# This file is part of the carrier_zip module for Tryton.
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.pool import PoolMeta
2014-04-11 15:45:11 +02:00
from trytond.transaction import Transaction
2019-01-16 16:04:34 +01:00
class Sale(metaclass=PoolMeta):
2014-04-11 15:45:11 +02:00
__name__ = 'sale.sale'
def _get_carrier_selection_pattern(self):
pattern = super(Sale, self)._get_carrier_selection_pattern()
if self.shipment_address:
pattern['shipment_postal_code'] = self.shipment_address.postal_code
return pattern
2014-04-11 15:45:11 +02:00
def _get_carrier_context(self):
context = super(Sale, self)._get_carrier_context()
if self.carrier and self.carrier.carrier_cost_method == 'grid':
context['shipment_postal_code'] = (self.shipment_address
and self.shipment_address.postal_code or None)
2014-04-11 15:45:11 +02:00
return context
def create_shipment(self, shipment_type):
context = {}
if self.carrier:
context = self._get_carrier_context()
with Transaction().set_context(context):
2014-04-11 15:45:11 +02:00
return super(Sale, self).create_shipment(shipment_type)