[FIX] hr_commission: refactor readonly logic for no_commission field

H11044
This commit is contained in:
Jorge Che
2022-10-07 23:59:56 +00:00
parent 472dec8709
commit a2953c59a7
2 changed files with 15 additions and 10 deletions

View File

@@ -5,9 +5,3 @@ class ProductTemplate(models.Model):
_inherit = 'product.template'
no_commission = fields.Boolean('Exclude from Commissions')
can_edit_no_commission = fields.Boolean(compute='_compute_can_edit_no_commission')
def _compute_can_edit_no_commission(self):
can_edit = self.env.user.has_group('account.group_account_user')
for template in self:
template.can_edit_no_commission = can_edit

View File

@@ -7,11 +7,22 @@
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='options']" position="inside">
<field name="can_edit_no_commission" invisible="1"/>
<span class="d-inline-block">
<field name="no_commission" attrs="{'readonly': [('can_edit_no_commission', '=', False)]}"/>
<label for="no_commission"/>
</span>
<field name="no_commission" readonly="1"/>
<label for="no_commission"/>
</span>
</xpath>
</field>
</record>
<record id="product_template_form_view_manager" model="ir.ui.view">
<field name="name">product.template.common.form.inherit.manager</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="groups_id" eval="[(4, ref('account.group_account_user'))]"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='no_commission']" position="attributes">
<attribute name="readonly">0</attribute>
</xpath>
</field>
</record>