From 5f62ec0b5cc54e4f1f270d8ac1ee05752958cade Mon Sep 17 00:00:00 2001 From: svs-odoo Date: Thu, 2 Jan 2020 13:50:06 +0000 Subject: [PATCH] [FIX] product_expiry: default expiration_date Before this commit, the default `expiration_date` wasn't set when the move line was created with the help of multiple assign serial numbers button or when user wrote/copy-pasted a list of SN/LN. task-2166230 closes odoo/odoo#42809 X-original-commit: ff6126e8077031fb20eada5f3f9d8fd8a4a4c56a Signed-off-by: Simon Lejeune (sle) --- addons/product_expiry/models/stock_move.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/addons/product_expiry/models/stock_move.py b/addons/product_expiry/models/stock_move.py index 3334ed416ea..d0fc75be213 100644 --- a/addons/product_expiry/models/stock_move.py +++ b/addons/product_expiry/models/stock_move.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import datetime + from odoo import fields, models @@ -8,3 +10,13 @@ class StockMove(models.Model): _inherit = "stock.move" use_expiration_date = fields.Boolean( string='Use Expiration Date', related='product_id.use_expiration_date') + + def _generate_serial_move_line_commands(self, lot_names, origin_move_line=None): + """Override to add a default `expiration_date` into the move lines values.""" + move_lines_commands = super()._generate_serial_move_line_commands(lot_names, origin_move_line=origin_move_line) + if self.product_id.use_expiration_date: + date = fields.Datetime.today() + datetime.timedelta(days=self.product_id.expiration_time) + for move_line_command in move_lines_commands: + move_line_vals = move_line_command[2] + move_line_vals['expiration_date'] = date + return move_lines_commands