trytond-stock_lot_quantity/stock.py

47 lines
1.6 KiB
Python
Raw Permalink Normal View History

2014-07-07 16:51:34 +02:00
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.pool import PoolMeta, Pool
2019-12-12 10:40:24 +01:00
from trytond.pyson import Eval, If
2014-07-07 16:51:34 +02:00
from trytond.transaction import Transaction
2018-08-24 12:24:55 +02:00
class Lot(metaclass=PoolMeta):
2014-07-07 16:51:34 +02:00
__name__ = 'stock.lot'
@classmethod
def get_quantity(cls, lots, name):
"Return null instead of 0.0 if no locations in context"
pool = Pool()
User = pool.get('res.user')
Location = pool.get('stock.location')
2014-07-07 16:51:34 +02:00
if not Transaction().context.get('locations'):
user = User(Transaction().user)
warehouses = None
if user.warehouse:
warehouses = [user.warehouse]
else:
warehouses = Location.search(['type', '=', 'warehouse'])
if not warehouses:
return {}.fromkeys([l.id for l in lots], None)
locations = [w.storage_location.id for w in warehouses]
Transaction().set_context(locations=locations)
2014-07-07 16:51:34 +02:00
return super(Lot, cls).get_quantity(lots, name)
2018-08-24 12:24:55 +02:00
class Move(metaclass=PoolMeta):
2014-07-07 16:51:34 +02:00
__name__ = 'stock.move'
@classmethod
def __setup__(cls):
super(Move, cls).__setup__()
2019-12-12 10:40:24 +01:00
cls.lot.context['locations'] = If(Eval('from_location'),
[Eval('from_location')], [])
2014-07-07 16:51:34 +02:00
if 'from_location' not in cls.lot.depends:
2022-05-03 18:24:37 +02:00
cls.lot.depends.add('from_location')
cls.lot.loading = 'lazy'
if 'product' not in cls.lot.depends:
2022-05-03 18:24:37 +02:00
cls.lot.depends.add('product')
cls.lot.states['readonly'] |= ~Eval('product') | ~Eval('from_location')