From bfbd3e56fffd135cbc37dc8c95f76f1e1d112917 Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Wed, 31 May 2023 14:27:49 +0000 Subject: [PATCH] [FIX] product_expiry: make quant.expiration_date readonly PR odoo/odoo#109511 added in a related expiration_date field linked to its lot_id's expiration_date. This field was added as readonly=False, which was a mistake due to the following issues it causes: bug - the related dates (use_date, removal_date, alert_date) won't correctly update, this is easily fixable bug - [mostly a nuisance, but will be confusing for users], if there are 2 lines for the same lot (e.g. different locations) then updating the expiration_date for one line won't show in the other lines without a view refresh (could be fixed with custom JS, but not ideal) bad UX - cluttered view of editable values redundancy - the ability to edit the expiration_date is easily done by clicking on the lot name within the view or by opening the list view of the lots and batch editing dates For stable we will make this field readonly. This field and `removal_date` would ideally be removed since they would never be different from the lot value, but both need to remain stored since they are used for the removal_strategy_order and gathering non-expired lots/SNs. opw-3328901 closes odoo/odoo#123746 X-original-commit: d21d9259aef855c900169263db90873b736f3df6 Signed-off-by: Steve Van Essche Signed-off-by: Tiffany Chang --- addons/product_expiry/models/stock_quant.py | 22 +++---------------- .../views/stock_quant_views.xml | 9 +++----- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/addons/product_expiry/models/stock_quant.py b/addons/product_expiry/models/stock_quant.py index 29a6fee3cba..91e0ad1fc8a 100644 --- a/addons/product_expiry/models/stock_quant.py +++ b/addons/product_expiry/models/stock_quant.py @@ -7,25 +7,9 @@ from odoo import api, fields, models class StockQuant(models.Model): _inherit = 'stock.quant' - expiration_date = fields.Datetime(related='lot_id.expiration_date', store=True, readonly=False) - removal_date = fields.Datetime(related='lot_id.removal_date', store=True, readonly=False) - use_expiration_date = fields.Boolean(related='product_id.use_expiration_date', readonly=True) - - @api.model - def _get_inventory_fields_create(self): - """ Returns a list of fields user can edit when he want to create a quant in `inventory_mode`. - """ - res = super()._get_inventory_fields_create() - res += ['expiration_date', 'removal_date'] - return res - - @api.model - def _get_inventory_fields_write(self): - """ Returns a list of fields user can edit when he want to edit a quant in `inventory_mode`. - """ - res = super()._get_inventory_fields_write() - res += ['expiration_date', 'removal_date'] - return res + expiration_date = fields.Datetime(related='lot_id.expiration_date', store=True) + removal_date = fields.Datetime(related='lot_id.removal_date', store=True) + use_expiration_date = fields.Boolean(related='product_id.use_expiration_date') @api.model def _get_removal_strategy_domain_order(self, domain, removal_strategy, qty): diff --git a/addons/product_expiry/views/stock_quant_views.xml b/addons/product_expiry/views/stock_quant_views.xml index 8d2a4744c98..e9b21cba8d0 100644 --- a/addons/product_expiry/views/stock_quant_views.xml +++ b/addons/product_expiry/views/stock_quant_views.xml @@ -23,10 +23,8 @@ - - + + @@ -39,8 +37,7 @@ + optional="hide" invisible="context.get('hide_removal_date')"/>