Skip to Content
Menu
This question has been flagged
2 Replies
2690 Views

myview.xml

<odoo>

  <data>

    <record model = "ir.ui.view" id = "custom_expense.list">

      <field name = "name"> custom_expense list </field>

      <field name = "model"> custom_expense.custom_expense </field>

      <field name = "arch" type = "xml">

        <tree>

          <field name = "name" />

          <field name = "test" />    

        </tree>

      </field>

    </record>

    <record model = "ir.actions.act_window" id = "custom_expense.action_window">

      <field name = "name"> custom_expense </field>

      <field name = "res_model"> custom_expense.custom_expense </field>

      <field name = "view_mode"> tree, form </field>

    </record>


    <menuitem name = "custom_expense" id = "custom_expense.menu_root" />


    <menuitem name = "Menu 1" id = "custom_expense.menu_1" parent = "custom_expense.menu_root" />

    <menuitem name = "Submenu 1" id = "custom_expense.menu_1_list" parent = "custom_expense.menu_1"

              action = "custom_expense.action_window" />

  </data>

</odoo>


mymodel.py

from odoo import models, fields, api

class custom_expense (models.Model):

    _name = 'custom_expense.custom_expense'

    _inherit = 'hr.expense'


    test = fields.Char (string = 'Valuethird')


I would like to display "name" field from hr.expense model but I found error:    TypeError: Many2many fields custom_expense.custom_expense.tax_ids and hr.expense.tax_ids use the same table and columns - - -


Avatar
Discard
Author Best Answer

When I change my code like this, anythings are not shown at the Expense tag.

myiew.xml

<odoo>

  <data>

    <record model = "ir.ui.view" id = "custom_expense.list">

      <field name = "name"> custom_expense list </field>

      <field name = "model"> custom_expense.custom_expense </field>

      <field name = "arch" type = "xml">

        <tree>

          <field name = "name" />

        </tree>

      </field>

    </record>


    <record model = "ir.ui.view" id = "custom_expense.form">

      <field name = "name"> custom_expense form </field>

      <field name = "model"> custom_expense.custom_expense </field>

      <field name = "arch" type = "xml">

        <form>

          <sheet>

            <notebook>

              <page string = "Expense">

                  <tree>

                      <field name = "name" />

                      <field name = "date" />

                      <field name = "analytic_account_id" groups = "analytic.group_analytic_accounting" />

                      <field name = "analytic_tag_ids" widget = "many2many_tags" groups = "analytic.group_analytic_tags" />

                  </tree>

              </page>

              <page string = "Other Info">

              </page>

            </notebook>

          </sheet>

        </form>

      </field>

    </record>


    <record model = "ir.actions.act_window" id = "custom_expense.action_window">

      <field name = "name"> custom_expense </field>

      <field name = "res_model"> custom_expense.custom_expense </field>

      <field name = "view_mode"> tree, form </field>

    </record>

    <menuitem name = "custom_expense" id = "custom_expense.menu_root" action = "custom_expense.action_window" />

  </data>

</odoo>


mymodel.py

from odoo import models, fields, api

class custom_expense (models.Model):

    _name = 'custom_expense.custom_expense'

    test = fields.Char (string = 'Valuethird') 

    hr_expense_id = fields.Many2one ('hr.expense', string = 'Expense')

    name = fields.Char (related = 'hr_expense_id.name')

    date = fields.Date (related = 'hr_expense_id.date')

    analytic_account_id = fields.Many2one (related = 'hr_expense_id.analytic_account_id')

    analytic_tag_ids = fields.Many2many (related = 'hr_expense_id.analytic_tag_ids')


But I want to get like this(https://drive.google.com/open?id=1ODOSWUxwzPvDy0U0BmyfEY70gcgHoFms). I thought if I inherit the hr.expense model I can display any fields from the parent model (hr.expense) to my custom view. I tried if I inherit hr.expense view to my custom view, it also changes the parent view. I also don't want to do that.

Avatar
Discard
Best Answer

Hi,

Try the following code

.py

from odoo import models, fields, api

class CustomExpense (models.Model):

  _name = 'custom.expense'
test = fields.Char(string='Valuethird')
  hr_expense_id = fields.Many2one('hr.expense', string='Expense')


.xml

<odoo>
<data>
<record model="ir.ui.view" id="custom_expense.list">
<field name="name">custom_expense_list</field>
<field name="model">custom.expense</field>
<field name="arch" type="xml">
<tree>
<field name="test"/>
<field name="hr_expense_id"/>
</tree>
</field>
</record>
<record id="action_custom_expense_form" model="ir.actions.act_window">
<field name="name">Custom Expense</field>
<field name="res_model">custom.expense</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="custom_expense" id="custom_expense.menu_root" action="action_custom_expense_form"/>
</data>
</odoo>

Regards

Avatar
Discard