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.
|
2018-05-16 16:30:31 +02:00
|
|
|
from trytond.pool import PoolMeta
|
2014-07-07 16:51:34 +02:00
|
|
|
from trytond.pyson import Eval
|
|
|
|
from trytond.transaction import Transaction
|
|
|
|
|
|
|
|
__all__ = ['Lot', 'Move']
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
if not Transaction().context.get('locations'):
|
|
|
|
return {}.fromkeys([l.id for l in lots], None)
|
|
|
|
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 09:51:53 +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:
|
|
|
|
cls.lot.depends.append('from_location')
|
2015-10-05 11:38:07 +02:00
|
|
|
cls.lot.loading = 'lazy'
|
2016-08-04 16:58:58 +02:00
|
|
|
|
|
|
|
if 'product' not in cls.lot.depends:
|
|
|
|
cls.lot.depends.append('product')
|
2017-11-22 11:20:34 +01:00
|
|
|
cls.lot.states['readonly'] |= ~Eval('product') | ~Eval('from_location')
|