Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Add boolean field to Expense line

By
Paul Strinati
on 10/13/14, 2:15 AM 2,187 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()

2
Paul Strinati
On 10/13/14, 4:30 AM

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!

 

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']"

Ludo - Neobis
on 10/13/14, 4:38 AM

Thanks but I still get the validation error as above.

Paul Strinati
on 10/13/14, 4:42 AM

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?

Ludo - Neobis
on 10/13/14, 4:50 AM

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

Paul Strinati
on 10/13/14, 4:58 AM

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

Paul Strinati
on 10/13/14, 1:22 PM

Good! and thnx for sharing the solution.

Ludo - Neobis
on 10/14/14, 4:03 AM
0
Anand Patel
On 10/13/14, 2:48 AM

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>

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
on 10/13/14, 3:59 AM
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

Anand Patel
on 10/13/14, 7:30 AM

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
on 10/13/14, 7:43 AM
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

Anand Patel
on 10/14/14, 2:24 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/13/14, 2:15 AM
Seen: 2187 times
Last updated: 3/16/15, 8:10 AM