[FIX] product_expiry: propagate lot's expiration date

On a receipt, when defining the expiration date of a lot, the SML keeps
<today> as expiration date

To reproduce the issue:
1. Edit the operation type "Receipts":
    - Show Detailed Operations: True
    - Use Existing Lots/Serial Numbers: True
2. Create a product P:
    - Type: Storable
    - Tracking: By Lots
    - Expiration Date: Enabled
3. Create a planned receipt R with 1 x P
4. Mark R as Todo
5. Add a detailed operations:
    - 1 x P with new lot L
6. Edit the lot:
    - Expiration Date: <today + 7days>

Error: When saving the picking (with the lot updated), the expiration
date is incorrect (set to <today>).

OPW-2785256

closes odoo/odoo#88283

X-original-commit: dd78e43a6286f798c54cf6b3222d3861b9dad34f
Signed-off-by: Steve Van Essche <svs@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
Adrien Widart
2022-04-08 14:48:46 +02:00
parent 8e0ef46e32
commit b342db8cc9
2 changed files with 30 additions and 2 deletions
@@ -15,10 +15,12 @@ class StockMoveLine(models.Model):
' become dangerous and must not be consumed.')
is_expired = fields.Boolean(related='lot_id.product_expiry_alert')
@api.depends('product_id', 'picking_type_use_create_lots')
@api.depends('product_id', 'picking_type_use_create_lots', 'lot_id.expiration_date')
def _compute_expiration_date(self):
for move_line in self:
if move_line.picking_type_use_create_lots:
if not move_line.expiration_date and move_line.lot_id.expiration_date:
move_line.expiration_date = move_line.lot_id.expiration_date
elif move_line.picking_type_use_create_lots:
if move_line.product_id.use_expiration_date:
if not move_line.expiration_date:
move_line.expiration_date = fields.Datetime.today() + datetime.timedelta(days=move_line.product_id.expiration_time)
@@ -499,3 +499,29 @@ class TestStockLot(TestStockCommon):
new_date = datetime.today() + timedelta(days=15)
quant.with_user(self.demo_user).with_context(inventory_mode=True).write({'removal_date': new_date})
self.assertEqual(quant.removal_date, new_date)
def test_apply_lot_date_on_sml(self):
"""
When assigning a lot to a SML, if the lot has an expiration date,
the latter should be applied on the SML
"""
exp_date = fields.Datetime.today() + relativedelta(days=15)
lot = self.env['stock.lot'].create({
'name': 'Lot 1',
'product_id': self.apple_product.id,
'expiration_date': fields.Datetime.to_string(exp_date),
'company_id': self.env.company.id,
})
sml = self.env['stock.move.line'].create({
'location_id': self.supplier_location,
'location_dest_id': self.stock_location,
'product_id': self.apple_product.id,
'qty_done': 3,
'product_uom_id': self.apple_product.uom_id.id,
'lot_id': lot.id,
'company_id': self.env.company.id,
})
self.assertEqual(sml.expiration_date, exp_date)