0
votes

I have an existing field on sale.order named 'payment_term_id' that is populated when a customer is selected, it uses an onchange method to populate it, I inherited the field to add an attribute that makes the field readonly when a condition is not met. However, when I select a customer on sales order, the Payment terms field is populated but when I save the form the field becomes empty. Without this inheritance and adding the attributes, it works as expected. Here is my code

<xpath expr="//field[@name='payment_term_id']" position="attributes">
           
            <attribute name="attrs">{'readonly': [('credit_group', '=', False)]}</attribute>
 </xpath>

And this is the credit_group field within the model, this field just assigns True or False if a user has a particular group or not.

class SaleOrderInvoiceCredit(models.Model):
    _inherit = 'sale.order'

    credit_group = fields.Boolean(compute='_compute_credit_group')

    @api.multi
    def _compute_credit_group(self):
        group = self.env.user. \
            has_group('name_of_module.group_name')
        for rec in self:
            rec.credit_group = group
1

1 Answers

0
votes

Try this.Read only field does not save data.You need to used force_save if you want to save data in readonly field.

<xpath expr="//field[@name='payment_term_id']" position="replace">
           
    <field name="payment_term_id" attrs="{'readonly': [('credit_group', '=', False)]}" force_save='1'/>
    </xpath>