From 90e1454bf31e2ccfc67d015182a2b66b6974aa9f Mon Sep 17 00:00:00 2001 From: Sergio Morillo Date: Wed, 30 Nov 2016 19:21:13 +0100 Subject: [PATCH] Add default location in shipment out return. --- __init__.py | 3 ++- stock.py | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 9f1942e..e7c9224 100644 --- a/__init__.py +++ b/__init__.py @@ -3,7 +3,7 @@ from trytond.pool import Pool from .location import ProductCategoryLocation, Location from .product import Category -from .stock import ShipmentOut, ShipmentIn +from .stock import ShipmentOut, ShipmentIn, ShipmentOutReturn def register(): @@ -13,4 +13,5 @@ def register(): ProductCategoryLocation, ShipmentOut, ShipmentIn, + ShipmentOutReturn, module='stock_product_category_location', type_='model') diff --git a/stock.py b/stock.py index ee3c77e..da35770 100644 --- a/stock.py +++ b/stock.py @@ -2,7 +2,7 @@ # this repository contains the full copyright notices and license terms. from trytond.pool import PoolMeta -__all__ = ['ShipmentOut', 'ShipmentIn'] +__all__ = ['ShipmentOut', 'ShipmentOutReturn', 'ShipmentIn'] class ShipmentOut: @@ -23,6 +23,26 @@ class ShipmentOut: return {'warehouse': self.warehouse} +class ShipmentOutReturn: + __metaclass__ = PoolMeta + __name__ = 'stock.shipment.out.return' + + @classmethod + def _get_inventory_moves(cls, incoming_move): + res = super(ShipmentOutReturn, cls)._get_inventory_moves(incoming_move) + for c in res.product.categories: + _to_location = c.get_default_location( + **cls._get_default_location_params(incoming_move)) + if _to_location: + res.to_location = _to_location + break + return res + + @classmethod + def _get_default_location_params(cls, incoming_move): + return {'warehouse': incoming_move.shipment.warehouse} + + class ShipmentIn: __metaclass__ = PoolMeta __name__ = 'stock.shipment.in'