trytond-stock_product_categ.../stock.py
2018-07-05 12:38:50 +02:00

70 lines
2.1 KiB
Python

# The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.pool import PoolMeta
__all__ = ['ShipmentOut', 'ShipmentOutReturn', 'ShipmentIn']
class ShipmentOut:
__metaclass__ = PoolMeta
__name__ = 'stock.shipment.out'
def _get_inventory_move(self, move):
res = super(ShipmentOut, self)._get_inventory_move(move)
if not res:
return res
for c in res.product.categories:
_from_location = c.get_default_location(
**self._get_default_location_params())
if _from_location:
res.from_location = _from_location
break
return res
def _get_default_location_params(self):
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)
if not res:
return res
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'
@classmethod
def _get_inventory_moves(cls, incoming_move):
res = super(ShipmentIn, cls)._get_inventory_moves(incoming_move)
if not res:
return res
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}