Hi all, I'm current facing a issue on re-define fields when doing inheritance.
my code is like below:
PY file
class expenseNew(models.Model):
_name = 'expense_new.expense_new'
_inherits = { 'hr.expense':'expense_new_id' }
expense_new_id = fields.Many2one('hr.expense', help="This is a many2one field in expense_new module, and this field is used as a link to hr.expense module")
name = fields.Char(string='Expense Summary', readonly=True, required=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]})
XML file
<div class="oe_title">
<label for="name"/>
<h1>
<field name="name" placeholder="e.g. Lunch with Customer"/>
</h1>
</div>
<record id="expense_new_form_view" model="ir.ui.view">
<field name="name">expense_new.expense_new.form.view</field>
<field name="model">expense_new.expense_new</field>
<field name="arch" type="xml">
<form string="Expenses" class="o_expense_form">
<header> ...... </header>
<sheet>
<div class="oe_title">
<label for="name"/>
<h1>
<field name="name" placeholder="e.g. Lunch with Customer"/>
</h1>
</div>
......
default PY file
name = fields.Char(string='Expense Description', readonly=True, required=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]})
As you can see, compare to default, what I only changed is "string" attribute.
This code gives me following error message.
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set
[object with reference: name - name]
If I delete my re-define field "name" in my PY file, error disappear. But this is the correct way to overwrite original field, am I right? Or can someone point out what I missed? BTW, on the
Any help will be useful! Thanks a lot!
BTW, I'm able to input data but can't save it. error shows up when I trying to save record.
May be the is confusion between these two attributes readonly=True, required=True,
Try putting readonly=False