changeset 59164ad1766a in modules/stock_shipment_cost:default
details:
https://hg.tryton.org/modules/stock_shipment_cost?cmd=changeset&node=59164ad1766a
description:
Replace invisible state by readonly for field edited with checkbox
issue10431
review363351002
diffstat:
stock.py | 23 ++++++++++++-----------
view/shipment_out_form.xml | 10 ++++------
2 files changed, 16 insertions(+), 17 deletions(-)
diffs (66 lines):
diff -r 0a61848071bc -r 59164ad1766a stock.py
--- a/stock.py Tue Apr 12 00:15:35 2022 +0200
+++ b/stock.py Tue Apr 12 20:28:14 2022 +0200
@@ -35,19 +35,17 @@
cost_used = fields.Function(fields.Numeric(
"Cost", digits=price_digits,
states={
- 'invisible': Eval('cost_edit', False),
+ 'readonly': (Eval('state').in_(['done', 'cancelled'])
+ | ~Eval('cost_edit', False)),
}),
- 'on_change_with_cost_used')
+ 'on_change_with_cost_used', setter='set_cost')
cost = fields.Numeric(
- "Cost", digits=price_digits,
- states={
- 'invisible': ~Eval('cost_edit', False),
- 'readonly': Eval('state').in_(['done', 'cancelled']),
- })
+ "Cost", digits=price_digits, readonly=True,)
cost_edit = fields.Boolean(
"Edit Cost",
states={
'readonly': Eval('state').in_(['done', 'cancelled']),
+ 'invisible': Eval('state').in_(['done', 'cancelled']),
},
help="Check to edit the cost.")
@@ -81,10 +79,13 @@
cost = self._compute_costs()['cost']
return cost
- @fields.depends('cost_edit', 'cost_used')
- def on_change_cost_edit(self):
- if self.cost_edit:
- self.cost = self.cost_used
+ @classmethod
+ def set_cost(cls, lines, name, value):
+ if name.endswith('_used'):
+ name = name[:-len('_used')]
+ cls.write([l for l in lines if l.cost_edit], {
+ name: value,
+ })
@property
def shipment_cost_moves(self):
diff -r 0a61848071bc -r 59164ad1766a view/shipment_out_form.xml
--- a/view/shipment_out_form.xml Tue Apr 12 00:15:35 2022 +0200
+++ b/view/shipment_out_form.xml Tue Apr 12 20:28:14 2022 +0200
@@ -8,12 +8,10 @@
</xpath>
<xpath expr="//page[@id='other']" position="before">
<page id="costs" string="Costs">
- <group id="costs" col="-1" colspan="4">
- <label name="cost"/>
- <label name="cost_used"/>
- <field name="cost"/>
- <field name="cost_used"/>
- <field name="cost_edit"/>
+ <label name="cost_used"/>
+ <group id="cost_used" col="-1" colspan="3">
+ <field name="cost_used" xexpand="0"/>
+ <field name="cost_edit" xexpand="0" xalign="0"/>
</group>
</page>
</xpath>