diff --git a/__init__.py b/__init__.py
index b180b19c44..57bb8a9ba7 100644
--- a/__init__.py
+++ b/__init__.py
@@ -5,6 +5,10 @@ from trytond.pool import Pool
from . import product
from . import stock
+from .stock import LotSledMixin
+
+__all__ = ['LotSledMixin', 'register']
+
def register():
Pool.register(
@@ -13,6 +17,7 @@ def register():
stock.Configuration,
stock.ConfigurationLotShelfLife,
stock.Lot,
+ stock.MoveAddLotsStartLot,
stock.Move,
stock.Period,
module='stock_lot_sled', type_='model')
diff --git a/stock.py b/stock.py
index b8146e3759..33b72d487b 100644
--- a/stock.py
+++ b/stock.py
@@ -45,8 +45,7 @@ class ConfigurationLotShelfLife(ModelSQL, ValueMixin):
shelf_life_delay = shelf_life_delay
-class Lot(metaclass=PoolMeta):
- __name__ = 'stock.lot'
+class LotSledMixin:
shelf_life_expiration_date = fields.Date('Shelf Life Expiration Date',
states={
@@ -85,7 +84,7 @@ class Lot(metaclass=PoolMeta):
pool = Pool()
Date = pool.get('ir.date')
try:
- super(Lot, self).on_change_product()
+ super().on_change_product()
except AttributeError:
pass
if self.product:
@@ -99,6 +98,10 @@ class Lot(metaclass=PoolMeta):
self.expiration_date = (today
+ datetime.timedelta(days=self.product.expiration_time))
+
+class Lot(LotSledMixin, metaclass=PoolMeta):
+ __name__ = 'stock.lot'
+
@classmethod
def write(cls, *args):
super(Lot, cls).write(*args)
@@ -138,6 +141,22 @@ class Lot(metaclass=PoolMeta):
move=move.rec_name))
+class MoveAddLotsStartLot(LotSledMixin, metaclass=PoolMeta):
+ __name__ = 'stock.move.add.lots.start.lot'
+
+ @fields.depends('shelf_life_expiration_date', 'expiration_date')
+ def _set_lot_values(self, lot):
+ super()._set_lot_values(lot)
+ self.shelf_life_expiration_date = lot.shelf_life_expiration_date
+ self.expiration_date = lot.expiration_date
+
+ def _get_lot_values(self, move):
+ values = super()._get_lot_values(move)
+ values['shelf_life_expiration_date'] = self.shelf_life_expiration_date
+ values['expiration_date'] = self.expiration_date
+ return values
+
+
class Move(metaclass=PoolMeta):
__name__ = 'stock.move'
diff --git a/stock.xml b/stock.xml
index b216fb1732..7f563dea7e 100644
--- a/stock.xml
+++ b/stock.xml
@@ -28,5 +28,11 @@ this repository contains the full copyright notices and license terms. -->
lot_tree
+
+
+ stock.move.add.lots.start.lot
+
+ lot_tree
+