Hi all, I'm really new to Odoo. yeah, again, I got another inheritance problem.
The issue I'm facing is that: After inheritance hr.expense to my custom module "expense_new", I would like to create new view to it, tree view seems works fine (maybe I did it wrong tho) but its form view display all the fields including new field I added. (all field display regardless its invisible attribute, more than 25 fields displayed on the screen). I believe It is something wrong on XML file.
The way I'm using to inherit is "_inherits", and here is my code:
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")
# ......Override original fields......
name = fields.Char(string='Expense Summary', readonly=True, required=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]})
...
# ......Extra fields/ my own fields......
calculate_total_amount = fields.Float(string='Total Cost', store=True, compute='_compute_amount_my', digits=dp.get_precision('Account'))
...
<record id="expense_new_tree_view" model="ir.ui.view">
<field name="name">expense_new.expense_new.tree.view</field>
<field name="model">expense_new.expense_new</field>
<field name="arch" type="xml">
<tree string="Expenses">
<field name="name"/>
<field name="employee_id"/>
<field name="date" required="True"/>
<field name="state"/>
<field name="calculate_total_amount"/>
</tree>
</field>
</record>
<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="inherit_id" ref="hr_expense.hr_expense_form_view"/>-->
<field name="arch" type="xml">
<form string="Expenses" class="o_expense_form">
<sheet>
......
<div class="oe_title">
<label for="name"/>
<h1>
<field name="name" placeholder="e.g. Lunch with Customer"/>
</h1>
</div>
<group>
<group>
<field name="date"/>
<field name="employee_id" groups="hr_expense.group_hr_expense_user"/>
<field name="calculate_total_amount"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
<record id="submit_your_expense_action" model="ir.actions.act_window">
<field name="name">My Expenses to Submit ("draft" expenses))</field>
<field name="res_model">expense_new.expense_new</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem .../>
And also, In "_inherits" way, is it possible to inherit its "hr_expense.hr_expense_form_view" view by using "inherit_id" on XML and add my own field to it? I guess I cant because, in terms of database, my own field doesn't stored in the "hr_expense" table but it is stored in my own database "expense_new.expense_new", am I right?
So, If I inherit a view then I should write <field name="model">original_module.model</field> and on the action, <field name="res_model">original_module.model</field> Otherwise (e.g. in this case) I use my own model name, right?
Can somebody please help me out, any hint, reference or suggestion will be useful. Thx a lot!