0
votes

I would like to add fields from my product.product to my newly created Expense form (legacy_expense) which inherits hr.expense.expense. I created this module to edit the workflow of the Expense Management module - this I managed to do fine.

I'm new to OpenERP and am having trouble getting this to work. I tried inheriting the many2one product_id field in the form through my .py field and then get it to show in the xml but it always comes up with the error "XMLSyntaxError: attributes construct error, line 25, column 13"

I'm guessing my inheritance ins't correct and I have no idea how to relate the two objects. If someone could help me out with this it'll be great!

This is my customised legacy_expense.py file:

from openerp.osv import fields, osv

class legacy_expense(osv.osv):


        _inherit = 'hr.expense.expense'

        _columns = {
        'state': fields.selection([

        ('draft', 'New'),
        ('cancelled', 'Refused'),
        ('confirm', 'Waiting Approval'),
        ('done', 'Paid'),

        ], 'Order State', readonly= False, select=True),


        'product_id': fields.many2one('product.product','Product',required=True),


  }

legacy_expense()

This is the legacy_expense.xml file:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <record id = "view_expenses_form_custom" model="ir.ui.view">
        <field name="name">view.expenses.form.custom</field>
        <field name="model">hr.expense.expense</field>
        <field name="type">form</field>
        <field name="inherit_id" ref="hr_expense.view_expenses_form" />
        <field name="arch" type="xml">

                <data>
                    <header>
                        <button name="signal_draft_to_confirm" states="draft" string="Submit" type="workflow" groups="base.group_hr_user" />
                    </header>

                <header>
                        <button name="signal_confirm_to_done" states="confirm" string="Approve Expense" type="workflow" groups="base.group_hr_user" />
                    </header>

                <header>
                        <button name="signal_confirm_to_refused" states="confirm" string="Reject Expense" type="workflow" groups="base.group_hr_user" />
                    </header>
                </data>
        <xpath expr = "/form/sheet/group/group[2]/field[@name='user_valid']"position="after">
                <field name="product_id"/>
        </xpath>
        </field>
    </record>
</data>
</openerp>

Again, thanks in advance to anyone who can help!

2

2 Answers

1
votes

Any field you want to show on a form for a model has to be on a model. In this case if you want to show fields from the product, the simplest is to set up a related field.

if, for example, you want to show the field "code" on product.product then add a column like this.

'product_code': fields.related('product_id', 'code', type = 'char', readonly = True)

and you can then just use the field in your view as:

<field name="product_code" />

Note the first argument to the related field is the name of your many2one field in your model that references product.product.

The other cool thing is you can chain these so you could do something like:

'currency_name': fields.related('product_id', 'company_id', 'currency_id', 'name', type = 'char', readonly = True)

There are a couple of gotchas if you want to refer to a related field such as a many2one on the related table. Have a look at the documentation for related fields in the developer momento on odoo.com

0
votes

There is nothing wrong in your inheritance or py file. The problem is with your xml file and it seems to be a syntax error. I believe that its got to do with the following line in ur xml file

<xpath expr = "/form/sheet/group/group[2]/field[@name='user_valid']"position="after">

Well add a space between the xpath expr and position, as follows:

<xpath expr = "/form/sheet/group/group[2]/field[@name='user_valid']" position="after">

This will solve your problem. Thanks And Regards