Auto add lote on internal ship move
This commit is contained in:
parent
d76d0e2c32
commit
0643296a97
17
stock.py
17
stock.py
|
@ -32,10 +32,25 @@ class Move(metaclass=PoolMeta):
|
|||
current_stock = fields.Function(fields.Float('Current Stock',
|
||||
depends=['product']), 'on_change_with_current_stock')
|
||||
|
||||
@fields.depends('current_stock')
|
||||
def next_lot(self, product_id):
|
||||
"Look for the oldest lot or the one closest to the expiration date."
|
||||
Lot = Pool().get('stock.lot')
|
||||
dom = [
|
||||
('product', '=', product_id),
|
||||
('active', '=', True),
|
||||
('quantity', '>', 0),
|
||||
]
|
||||
|
||||
lots = Lot.search(dom, order=[('create_date', 'ASC')])
|
||||
if lots:
|
||||
return lots[0].id
|
||||
|
||||
@fields.depends('current_stock', 'lot')
|
||||
def on_change_product(self, name=None):
|
||||
super(Move, self).on_change_product()
|
||||
self.current_stock = self.on_change_with_current_stock()
|
||||
if self.product:
|
||||
self.lot = self.next_lot(self.product.id)
|
||||
|
||||
@fields.depends('product', 'from_location', 'to_location')
|
||||
def on_change_with_current_stock(self, name=None):
|
||||
|
|
Loading…
Reference in New Issue