Files
tryton/location.py
T

60 lines
2.2 KiB
Python
Raw Normal View History

#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
2009-02-28 17:06:12 +01:00
from trytond.model import ModelView, ModelSQL, fields
2010-01-20 11:05:08 +01:00
from trytond.pyson import If, Eval, Bool
from trytond.transaction import Transaction
from trytond.backend import TableHandler
2012-09-24 22:18:22 +02:00
from trytond.pool import PoolMeta
__all__ = ['ProductLocation', 'ShipmentIn']
__metaclass__ = PoolMeta
2009-02-28 17:06:12 +01:00
class ProductLocation(ModelSQL, ModelView):
'''
2012-09-24 22:18:22 +02:00
Product Location
It defines the default storage location by warehouse for a product.
'''
2012-09-24 22:18:22 +02:00
__name__ = 'stock.product.location'
product = fields.Many2One('product.product', 'Product', required=True,
2012-03-05 10:53:09 +01:00
select=True)
warehouse = fields.Many2One('stock.location', 'Warehouse', required=True,
domain=[('type', '=', 'warehouse')])
location = fields.Many2One('stock.location', 'Storage Location',
2011-08-04 16:57:45 +02:00
required=True, domain=[
('type', '=', 'storage'),
('parent', 'child_of', If(Bool(Eval('warehouse')),
2010-01-20 11:05:08 +01:00
[Eval('warehouse')], [])),
2011-08-04 16:57:45 +02:00
], depends=['warehouse'])
2012-05-14 15:36:57 +02:00
sequence = fields.Integer('Sequence',
order_field='(%(table)s.sequence IS NULL) %(order)s, '
'%(table)s.sequence %(order)s')
2012-09-24 22:18:22 +02:00
@classmethod
def __setup__(cls):
super(ProductLocation, cls).__setup__()
cls._order.insert(0, ('sequence', 'ASC'))
2012-09-24 22:18:22 +02:00
@classmethod
def __register__(cls, module_name):
2012-05-14 15:36:57 +02:00
cursor = Transaction().cursor
2012-09-24 22:18:22 +02:00
table = TableHandler(cursor, cls, module_name)
2012-05-14 15:36:57 +02:00
2012-09-24 22:18:22 +02:00
super(ProductLocation, cls).__register__(module_name)
2012-05-14 15:36:57 +02:00
# Migration from 2.4: drop required on sequence
table.not_null_action('sequence', action='remove')
2012-09-24 22:18:22 +02:00
class ShipmentIn:
__name__ = 'stock.shipment.in'
2012-09-24 22:18:22 +02:00
@classmethod
def _get_inventory_moves(cls, incoming_move):
res = super(ShipmentIn, cls)._get_inventory_moves(incoming_move)
for product_location in incoming_move.product.locations:
if product_location.warehouse.id != \
2009-09-30 08:11:27 +02:00
incoming_move.shipment_in.warehouse.id:
continue
res['to_location'] = product_location.location.id
return res