Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Add boolean field to Expense line

Subscribe

Get notified when there's activity on this post

This question has been flagged
hrxmlviewexpense
2 Replies
8782 Views
Avatar
Paul Strinati

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()

0
Avatar
Discard
Avatar
Paul Strinati
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!

 

2
Avatar
Discard
Ludo - 21South

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

Paul Strinati
Author

Thanks but I still get the validation error as above.

Ludo - 21South

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?

Paul Strinati
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

Paul Strinati
Author

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

Ludo - 21South

Good! and thnx for sharing the solution.

Avatar
Anand Patel
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>

0
Avatar
Discard
Paul Strinati
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

OdooBot
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

Paul Strinati
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?

OdooBot
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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How do I remove a button from the sale.order.form? Solved
xml view
Avatar
Avatar
Avatar
Avatar
Avatar
6
Sep 17
9507
display view if user is anonymous
xml view
Avatar
Avatar
1
Mar 15
5243
How do I change default text from a module view?
xml view
Avatar
Avatar
1
Mar 15
7010
XML from module not loaded after changes.
xml view
Avatar
Avatar
2
Mar 15
10976
view xml, attrs use variable with attribute Solved
attrs xml view
Avatar
Avatar
1
Mar 24
11616
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now