[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 <svs@odoo.com> Signed-off-by: Tiffany Chang <tic@odoo.com>
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -23,10 +23,8 @@
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='lot_id']" position="after">
|
||||
<field name="use_expiration_date" invisible="1"/>
|
||||
<field name="expiration_date" optional="hide" invisible="context.get('hide_removal_date')"
|
||||
attrs="{'readonly': ['|', ('tracking', '=', 'none'), ('use_expiration_date', '=', False)]}"/>
|
||||
<field name="removal_date" optional="hide"
|
||||
invisible="context.get('hide_removal_date')" attrs="{'readonly': ['|', ('tracking', '=', 'none'), ('use_expiration_date', '=', False)]}"/>
|
||||
<field name="expiration_date" optional="hide" invisible="context.get('hide_removal_date')"/>
|
||||
<field name="removal_date" optional="hide" invisible="context.get('hide_removal_date')"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
@@ -39,8 +37,7 @@
|
||||
<xpath expr="//field[@name='lot_id']" position="after">
|
||||
<field name="use_expiration_date" invisible="1"/>
|
||||
<field name="expiration_date" groups="stock.group_production_lot"
|
||||
optional="hide" invisible="context.get('hide_removal_date')"
|
||||
attrs="{'readonly': ['|', '|', ('tracking', '=', 'none'), ('lot_id', '=', False), ('use_expiration_date', '=', False)]}"/>
|
||||
optional="hide" invisible="context.get('hide_removal_date')"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user