30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
# 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
|
|
from trytond.transaction import Transaction
|
|
|
|
__all__ = ['Sale']
|
|
|
|
|
|
class Sale:
|
|
__metaclass__ = PoolMeta
|
|
__name__ = 'sale.sale'
|
|
|
|
def _get_carrier_selection_pattern(self):
|
|
pattern = super(Sale, self)._get_carrier_selection_pattern()
|
|
if self.shipment_address:
|
|
pattern['shipment_zip'] = self.shipment_address.zip
|
|
return pattern
|
|
|
|
def _get_carrier_context(self):
|
|
context = super(Sale, self)._get_carrier_context()
|
|
if self.carrier and self.carrier.carrier_cost_method == 'grid':
|
|
context['shipment_zip'] = (self.shipment_address
|
|
and self.shipment_address.zip or None)
|
|
return context
|
|
|
|
def create_shipment(self, shipment_type):
|
|
with Transaction().set_context(self._get_carrier_context()):
|
|
return super(Sale, self).create_shipment(shipment_type)
|