changeset 098c5c30870d in modules/stock_package_shipping_ups:default
details:
https://hg.tryton.org/modules/stock_package_shipping_ups?cmd=changeset;node=098c5c30870d
description:
Manage shipping for supplier shipment returns
We move the shipping code in mixin's such that it can be applied on
other
shipments.
We define properties to abstract the information needed by the create
shipping
wizards. Such that they can be execute on any shipment.
issue9850
review324521002
diffstat:
__init__.py | 1 +
stock.py | 30 ++++++++++++++++++------------
2 files changed, 19 insertions(+), 12 deletions(-)
diffs (78 lines):
diff -r fb5551b526e6 -r 098c5c30870d __init__.py
--- a/__init__.py Sat Dec 19 17:08:47 2020 +0100
+++ b/__init__.py Sun Dec 20 19:54:48 2020 +0100
@@ -11,6 +11,7 @@
Pool.register(
stock.PackageType,
stock.ShipmentOut,
+ stock.ShipmentInReturn,
carrier.CredentialUPS,
carrier.Carrier,
module='stock_package_shipping_ups', type_='model')
diff -r fb5551b526e6 -r 098c5c30870d stock.py
--- a/stock.py Sat Dec 19 17:08:47 2020 +0100
+++ b/stock.py Sun Dec 20 19:54:48 2020 +0100
@@ -60,19 +60,18 @@
return None
-class ShipmentOut(metaclass=PoolMeta):
- __name__ = 'stock.shipment.out'
+class ShippingUPSMixin:
def validate_packing_ups(self):
- warehouse_address = self.warehouse.address
- if not warehouse_address:
+ warehouse = self.shipping_warehouse
+ if not warehouse.address:
raise PackingValidationError(
gettext('stock_package_shipping_ups'
'.msg_warehouse_address_required',
shipment=self.rec_name,
- warehouse=self.warehouse.rec_name))
- if warehouse_address.country != self.delivery_address.country:
- for party in {self.customer, self.company.party}:
+ warehouse=warehouse.rec_name))
+ if warehouse.address.country != self.delivery_address.country:
+ for party in {self.shipping_to, self.company.party}:
for mechanism in party.contact_mechanisms:
if mechanism.type in ('phone', 'mobile'):
break
@@ -92,6 +91,14 @@
shipment=self.rec_name))
+class ShipmentOut(ShippingUPSMixin, metaclass=PoolMeta):
+ __name__ = 'stock.shipment.out'
+
+
+class ShipmentInReturn(ShippingUPSMixin, metaclass=PoolMeta):
+ __name__ = 'stock.shipment.in.return'
+
+
class CreateShipping(metaclass=PoolMeta):
__name__ = 'stock.shipment.create_shipping'
@@ -294,9 +301,8 @@
}
def get_request(self, shipment, packages, credential):
- warehouse_address = shipment.warehouse.address
- shipper = self.get_shipping_party(shipment.company.party,
- warehouse_address)
+ shipper = self.get_shipping_party(
+ shipment.company.party, shipment.shipping_warehouse.address)
shipper['ShipperNumber'] = credential.account_number
packages = [self.get_package(credential.use_metric, p)
@@ -309,8 +315,8 @@
'Shipment': {
'Description': (shipment.shipping_description or '')[:50],
'Shipper': shipper,
- 'ShipTo': self.get_shipping_party(shipment.customer,
- shipment.delivery_address),
+ 'ShipTo': self.get_shipping_party(
+ shipment.shipping_to, shipment.shipping_to_address),
'PaymentInformation': self.get_payment_information(
shipment, credential),
'Service': {