This question has been flagged
1 Reply
4936 Views

Hi , I'm working on openErp 7.0 ,on the module Timesheet i want to add 2 attributes to the tree view (start_at and end_at) but when updating the module i have the following error message : * Invalid XML for View Architecture!'* would some one tell me what i should correct in the following xml and python code : My XML hr_timesheet_view.xml

<record id="hr_timesheet_line_tree" model="ir.ui.view">
        <field name="name">hr.analytic.timesheet.tree</field>
        <field name="model">hr.analytic.timesheet</field>
        <field name="arch" type="xml">
            <tree editable="top" string="Timesheet Activities" version="7.0">                  
                <field name="date" on_change="on_change_date(date)"/>
                <field name="user_id" on_change="on_change_user_id(user_id)" required="1" options='{"no_open": True}'/>
                <field name="name"/>
                <field domain="[('type','=','normal'),('use_timesheets','=',1)]" name="account_id" context="{'default_use_timesheets': 1, 'default_type': 'contract'}"/>                                        
                <field name="unit_amount" string="Duration" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id)" sum="Total time" widget="float_time"/>                    
                <field name="start_at"/>
                <field name="end_at"/>
                <field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id)" invisible="1"/>
                <field name="journal_id" invisible="1"/>                    
                <field name="amount" sum="Total cost" invisible="1"/>
                <field name="general_account_id" invisible="1"/>
                <field name="product_id" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id)" required="1" domain="[('type','=','service')]" invisible="1"/>
            </tree>
        </field>
    </record>

my python code :

class hr_analytic_timesheet(osv.osv):
_name = "hr.analytic.timesheet"
_table = 'hr_analytic_timesheet'
_description = "Timesheet Line"
_inherits = {'account.analytic.line': 'line_id'}
_order = "id desc"
_columns = {
    'line_id': fields.many2one('account.analytic.line', 'Analytic Line', ondelete='cascade', required=True),
    'partner_id': fields.related('account_id', 'partner_id', type='many2one', string='Partner', relation='res.partner', store=True),                
    'start_at':fields.text('from'),
    'end_at':fields.text('to'),

}

With regards

Avatar
Discard
Best Answer

Hi,

should not modify the original code openerp , if you want add fields must create a

new module :

your_file.py

from osv import osv, fields
class hr_analytic_timesheet(osv.osv):
    _inherit = "hr.analytic.timesheet"
    _columns = {
               'start_at':fields.char('from'),
               'end_at':fields.char('to'),
                }          
hr_analytic_timesheet()

your_file.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record model="ir.ui.view" id="hr_timesheet_inherit">
            <field name="name">hr_timesheet_inherit_tree</field>
            <field name="model">hr.analytic.timesheet</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree" />
            <field name="arch" type="xml">
                <xpath expr="//field[@name='unit_amount']" position="after">
                    <field name="start_at" />
                    <field name="end_at" />
                </xpath>

            </field>
        </record>
    </data>
</openerp>
Avatar
Discard

Another thing to do when modifying code, is to restart the openERP server, than reload the module (Settings -> installed modules -> search for module and click on it -> Click button Upgrade)

Author

Thank's a lot , it works now :)