This question has been flagged
2 Replies
7435 Views

I'm trying to add a boolean field to the expense line in hr.expense, but am struggling to find the relevant object and view names in Developer mode. I'm doing it as a custom module, but need some help with the onetomany relationship between hr.expense.expense, and hr.expense.line (i.e. I cannot figure out the view that I need to edit for the line item).

Basically I just want to add the boolen field at the end of the line (i.e. after the total field) - any pointers greatly appreciated!

This is the XML I'm using in the custom module:


<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <record model="ir.ui.view" id="ocl_hr_expense">
      <field name="name">hr.expense.line.tree</field>
      <field name="model">hr.expense.line</field>
      <field name="inherit_id" ref="hr_expense.hr_expense_form_view" />
      <field name="arch" type="xml">
        <xpath expr="//page[@string='Description']/field[@name='line_ids']/tree[@string='Expense Lines']/field[@name='total_amount']" position="after">
          <field name="abc" />
        </xpath>
      </field>
    </record>
  </data>
</openerp>

and my boolean field is defined as follows:

from openerp.osv import fields, osv

class ocl_hr_expense(osv.osv):

    _inherit = "hr.expense.line"

    _columns = {
        'abc': fields.boolean('ABC Reportable')
    }

    _defaults ={
        'abc': 0
    }

ocl_hr_expense()

Avatar
Discard
Author Best Answer

Solution - I was using the wrong model - I should have been using hr.expense.expense instead of hr.expense.line (I assumed because I wanted to add something to the line, I should use hr.expense.line - duh!). So my XML file is now:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <record model="ir.ui.view" id="ocl_hr_expense">
      <field name="name">hr.expense.line.tree</field>
      <field name="model">hr.expense.expense</field>
      <field name="inherit_id" ref="hr_expense.view_expenses_form" />
      <field name="arch" type="xml">
        <xpath expr="/form/sheet/notebook/page[@string='Description']/field[@name='line_ids']/tree[@string='Expense Lines']/field[@name='name']" position="after">
          <field name="abc" />
        </xpath>
      </field>
    </record>
  </data>
</openerp>

and it works a dream!

 

Avatar
Discard

Try adding two slashes instead of just one between all the elements in your xpath. So like: "//page[@string='Description']//field[@name='line_ids']//tree[@string='Expense Lines']//field[@name='total_amount']"

Author

Thanks but I still get the validation error as above.

Around the error should be the exact part the XML is failing on. For example "Field X could not be found on view for Y". Could you update your issue with said error?

Author

I've checked the openerp-server.log file and found this: openerp.osv.orm: Can't find field 'message_follower_ids' in the following view parts composing the view of object model 'hr.expense.expense': * hr.expense.form Either you wrongly customized this view, or some modules bringing those views are not compatible with your current data model

Author

I've re-posted my solution as I've now got it working :)

Good! and thnx for sharing the solution.

Best Answer

Hi,

you need to add boolean field in r.expense.line and then you have to inherit the hr.expense.expense form view and put that filed by xpath like example given below
<xpath expr="//page[@string='Order Lines']/field[@name='order_line']/tree[@string='Sales Order Lines']/field[@name='product_id']" position="after">

<field name="your_booleans_field" />

</xpath>

Avatar
Discard
Author

Thanks Anand - I've created the boolean field in hr.expense.line, but it's the view name and xpath I'm struggling with as I cannot seem to construct the correct string. I'm trying this: hr.expense.line.tree hr.expense.line But it doesn't seem to like the view name: ValueError: No such external ID currently defined in the system: hr_expense.hr_expense_view and I cannot seem to find the correct view name anywhere. I was trying to work off this one: https://github.com/vnc-biz/openerp-addons-bundle/blob/master-7.0/hr_expense/hr_expense_view.xml

Hi,

when you activate developer mode on the top of the form you will find one drop-down shown in the attached image(developer_mode.png)
from there you will find option for the "edit form view"
there you will find (external_id.png) so take that value and pass it in the xpath



On Mon, Oct 13, 2014 at 1:29 PM, Paul Strinati <paul.strinati@optimumcredit.co.uk> wrote:

Thanks Anand - I've created the boolean field in hr.expense.line, but it's the view name and xpath I'm struggling with as I cannot seem to construct the correct string. I'm trying this: hr.expense.line.tree hr.expense.line But it doesn't seem to like the view name: ValueError: No such external ID currently defined in the system: hr_expense.hr_expense_view and I cannot seem to find the correct view name anywhere. I was trying to work off this one: https://github.com/vnc-biz/openerp-addons-bundle/blob/master-7.0/hr_expense/hr_expense_view.xml

--
Paul Strinati
Sent by OpenERP S.A. using Odoo about Forum Post False



--
Thanks,

Anand Patel
+91 9601663735

Author

Thanks Anand - I've got the correct External ID now (hr_expense.view_expenses_form), but am now getting a weird error message in the log to do with the parsing of the XML: openerp.osv.orm: Can't find field 'message_follower_ids' in the following view parts composing the view of object model 'hr.expense.expense': * hr.expense.form Some kind of inheritance issue?

Hi,

you need to add following code to the python file.
_inherit = ['mail.thread']

On Mon, Oct 13, 2014 at 5:13 PM, Paul Strinati <paul.strinati@optimumcredit.co.uk> wrote:

Thanks Anand - I've got the correct External ID now (hr_expense.view_expenses_form), but am now getting a weird error message in the log to do with the parsing of the XML: openerp.osv.orm: Can't find field 'message_follower_ids' in the following view parts composing the view of object model 'hr.expense.expense': * hr.expense.form Some kind of inheritance issue?

--
Paul Strinati
Sent by OpenERP S.A. using Odoo about Forum Post False



--
Thanks,

Anand Patel
+91 9601663735