From db727601751a1787dcfdfba860e5bf51b315f1ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 20 Dec 2020 19:54:48 +0100 Subject: [PATCH] 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 --- __init__.py | 1 + stock.py | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/__init__.py b/__init__.py index 3a1c8bcb53..1f22fa7869 100644 --- a/__init__.py +++ b/__init__.py @@ -12,6 +12,7 @@ def register(): carrier.CredentialDPD, carrier.Carrier, stock.ShipmentOut, + stock.ShipmentInReturn, module='stock_package_shipping_dpd', type_='model') Pool.register( stock.CreateShipping, diff --git a/stock.py b/stock.py index f5a5890fb0..3aeb47a886 100644 --- a/stock.py +++ b/stock.py @@ -21,17 +21,24 @@ from .configuration import get_client, SHIPMENT_SERVICE from .exceptions import DPDError -class ShipmentOut(metaclass=PoolMeta): - __name__ = 'stock.shipment.out' +class ShippingDPDMixin: def validate_packing_dpd(self): - warehouse_address = self.warehouse.address - if not warehouse_address: + warehouse = self.shipping_warehouse + if not warehouse.address: raise PackingValidationError( gettext('stock_package_shipping_dpd' '.msg_warehouse_address_required', shipment=self.rec_name, - warehouse=self.warehouse.rec_name)) + warehouse=warehouse.rec_name)) + + +class ShipmentOut(ShippingDPDMixin, metaclass=PoolMeta): + __name__ = 'stock.shipment.out' + + +class ShipmentInReturn(ShippingDPDMixin, metaclass=PoolMeta): + __name__ = 'stock.shipment.in.return' class CreateShipping(metaclass=PoolMeta): @@ -218,9 +225,10 @@ class CreateDPDShipping(Wizard): 'sendingDepot': credential.depot, 'product': shipment.carrier.dpd_product, 'sender': self.shipping_party( - shipment.company.party, shipment.warehouse.address), + shipment.company.party, + shipment.shipping_warehouse.address), 'recipient': self.shipping_party( - shipment.customer, shipment.delivery_address), + shipment.shipping_to, shipment.shipping_to_address), }, 'parcels': [self.get_parcel(p) for p in packages], 'productAndServiceData': {