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.
|
2016-11-28 16:27:11 +01:00
|
|
|
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'
|
|
|
|
|
2016-11-28 16:27:11 +01:00
|
|
|
def _get_carrier_selection_pattern(self):
|
|
|
|
pattern = super(Sale, self)._get_carrier_selection_pattern()
|
|
|
|
if self.shipment_address:
|
2021-04-01 16:27:51 +02:00
|
|
|
pattern['shipment_postal_code'] = self.shipment_address.postal_code
|
2016-11-28 16:27:11 +01:00
|
|
|
return pattern
|
2014-04-11 15:45:11 +02:00
|
|
|
|
|
|
|
def _get_carrier_context(self):
|
|
|
|
context = super(Sale, self)._get_carrier_context()
|
2014-04-25 11:28:49 +02:00
|
|
|
if self.carrier and self.carrier.carrier_cost_method == 'grid':
|
2021-04-01 16:27:51 +02:00
|
|
|
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):
|
2016-11-30 15:52:58 +01:00
|
|
|
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)
|