Replace invisible state by readonly for field edited with checkbox

issue10431
review363351002
This commit is contained in:
Maxime Richez committed 2022-04-12 20:28:14 +02:00
1 parent dc3519624a
commit d06e2470b8
2 files changed
+26 -17

No files matched your search

+25 -15
View File
@@ -1168,29 +1168,27 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
'To Location'), 'get_to_location')
delivery_date = fields.Function(fields.Date('Delivery Date',
states={
'invisible': ((Eval('type') != 'line')
| (Eval('delivery_date_edit', False)
& ~Eval('purchase_state').in_(
['processing', 'done', 'cancelled']))),
'invisible': Eval('type') != 'line',
'readonly': (Eval('purchase_state').in_(
['processing', 'done', 'cancelled'])
| ~Eval('delivery_date_edit', False)),
}),
'on_change_with_delivery_date')
'on_change_with_delivery_date', setter='set_delivery_date')
delivery_date_edit = fields.Boolean(
"Edit Delivery Date",
states={
'invisible': Eval('type') != 'line',
'readonly': Eval('purchase_state').in_([
'processing', 'done', 'cancelled']),
'invisible': (
(Eval('type') != 'line')
| Eval('purchase_state').in_(
['processing', 'done', 'cancelled'])),
'readonly': Eval('purchase_state').in_(
['processing', 'done', 'cancelled']),
},
help="Check to edit the delivery date.")
delivery_date_store = fields.Date(
"Delivery Date",
"Delivery Date", readonly=True,
states={
'invisible': ((Eval('type') != 'line')
| ~Eval('delivery_date_edit', False)
| Eval('purchase_state').in_(
['processing', 'done', 'cancelled'])),
'readonly': Eval('purchase_state').in_([
'processing', 'done', 'cancelled']),
'invisible': Eval('type') != 'line',
})
purchase_state = fields.Function(
fields.Selection('get_purchase_states', 'Purchase State'),
@@ -1454,6 +1452,18 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
return min(dates, default=None)
return self.planned_delivery_date
@classmethod
def set_delivery_date(cls, lines, name, value):
cls.write([l for l in lines if l.delivery_date_edit], {
'delivery_date_store': value,
})
@fields.depends('delivery_date_edit', 'delivery_date',
methods=['planned_delivery_date'])
def on_change_delivery_date_edit(self):
if not self.delivery_date_edit:
self.delivery_date = self.planned_delivery_date
@property
@fields.depends(
'product_supplier', 'quantity', 'purchase',
+1 -2
View File
@@ -26,8 +26,7 @@ this repository contains the full copyright notices and license terms. -->
<label id="delivery_date" string="Delivery Date:"/>
<group id="delivery_date" col="-1">
<field name="delivery_date" xexpand="0"/>
<field name="delivery_date_store" xexpand="0"/>
<field name="delivery_date_edit" xexpand="0"/>
<field name="delivery_date_edit" xexpand="0" xalign="0"/>
</group>
<separator name="description" colspan="4"/>
<field name="description" colspan="4"/>