Odoo 9 add column to grid view - view

I'm create simple module with 4 fields (name,date,user,description).Below is my .xml file.
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_my_report_form" model="ir.ui.view">
<field name="name">penalty.form</field>
<field name="model">my.report</field>
<field eval="2" name="priority"/>
<field name="arch" type="xml">
<form string="Project">
<sheet string="My report">
<group>
<div class="oe_title">
<h1 class="o_row">
<field name="name" placeholder="Name..." />
</h1>
</div>
</group>
<group>
<field name="user" placeholder="User..."/>
</group>
<group>
<field name="date" placeholder="Date..."/>
</group>
<notebook>
<page name="description_page" string="Description">
<field name="description"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_my_report_form">
<field name="name">Add new</field>
<field name="res_model">my.report</field>
</record>
<menuitem name="MY report" id="menu_penalty" action="action_my_izvjestaj_form" sequence="1"/>
</data>
</openerp>
When open from menu in grid view visble is only name.
https://postimg.org/image/ccms5aww3/
How add date and user fields?

You need to declare Tree view for that model.
<!-- Tree Views BEGIN-->
<record model="ir.ui.view" id="view_my_report_tree">
<field name="name">penalty.tree</field>
<field name="model">my.form</field>
<field name="arch" type="xml">
<tree string="Project">
<field name="name"/>
<field name="user"/>
<field name="date"/>
</tree>
</field>
</record>

Related

AssertionError: Element odoo has extra content: record, line 4

I'm trying to add multi field to timesheet module to work as a tasks manage app i did inheritance to account.analytic.line the problem is in the view i got that error "AssertionError: Element odoo has extra content: record, line 4"
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="todo_timesheet_line_tree" model="ir.ui.view">
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
<field name="model">account.analytic.line</field>
<field name="arch" type="xml"/>
<field name="task_id" position="after">
<field name="priority"/>
</field>
<field name="company_id" groups="base.group_multi_company" position="before">
<field name="gov_department"/>
<field name="priority"/>
<field name="date_deadline"/>
</field>
</record>
</odoo>
from odoo import models, fields, api
class TodoTask(models.Model):
_inherit = 'account.analytic.line'
startdate=fields.Date('start Date', required=True, index=True, default=fields.Date.context_today)
date_deadline=fields.Date('Deadline', required=True, index=True, default=fields.Date.context_today)
priority = fields.Selection(selection=[('1', 'فوري'), ('2','هام جدا' ),('3','اقل اهمية')])
is_done = fields.Boolean ('Done?')
gov_department = fields.Many2one('govauthority','الجهة الحكومية')
class govauthority(models.Model):
govname = fields.Char('GOV_Department', size=25, required=True)
The error is in this line
<field name="arch" type="xml" />
You closed the tag while you really should not. Within this tag the actual XML body should be.
<record id="todo_timesheet_line_tree" model="ir.ui.view">
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree" />
<field name="model">account.analytic.line</field>
<field name="arch" type="xml">
<field name="task_id" position="after">
<field name="priority" />
</field>
<field name="company_id" groups="base.group_multi_company" position="before">
<field name="gov_department" />
<field name="priority" />
<field name="date_deadline" />
</field>
</field>
</record>

How to correctly inherit an inherited view in odoo?

I have been trying to target an inherited element in the view, but it's not working for me.
So I have a view that inherits from the form view of hr.contract as shown here:
<record id="hr_contract_view_form_cayor" model="ir.ui.view">
<field name="name">name</field>
<field name="model">hr.contract</field>
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
<field name="arch" type="xml">
<data>
<!-- more elements define with xpath -->
<xpath expr="//field[#name='job_id']" position="after">
<field name="retirement_age"/>
</xpath>
...
<xpath expr="//page[#name='information']" position="after">
<page string="Allowances" groups="hr_payroll.group_hr_payroll_user">
<group>
<group name="allowances_group1">
...
<field name="car_allowance"/>
...
</group>
<group name="allowances_group2">
...
</group>
</group>
</page>
</xpath>
</data>
</field>
</record>
I have defined a new file to inherit from this form view, which adds a new field to it, as follows:
<record id="hr_contract.hr_contract_view_form_inherited" model="ir.ui.view">
<field name="name">hr.contract.grade.rank.form.inherit</field>
<field name="model">hr.contract</field>
<field name="inherit_id" ref="module.hr_contract_view_form_cayor"/>
<field name="arch" type="xml">
<data>
<xpath expr="//group[#name='allowances_group1']" position="inside">
<field name="medical_allowance" />
</xpath>
</data>
</field>
</record>
But when I upgrade my module, I get the following error:
Field `retirement_age` does not exist
How can I correctly inherit from the first one, and add my new field?
Any help will be greatly appreciated, thanks in advance.
Please try this code :
Python :
class HrContract(models.Model):
_inherit = 'hr.contract'
retirement_age = fields.Char(string="Retirement Age:")
XML :
<record id="hr_contract_view_form_cayor" model="ir.ui.view">
<field name="name">name</field>
<field name="model">hr.contract</field>
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
<field name="arch" type="xml">
<data>
<!-- more elements define with xpath -->
<xpath expr="//field[#name='job_id']" position="after">
<field name="retirement_age"/>
</xpath>
</data>
</field>
</record>

Tree view in odoo 11

I want to show the fields that i mentioned in the tree string when there are no records in my tree view instead of showing "Click to add a new Sample record."
<record model="ir.ui.view" id="sample_tree_view">
<field name="name">Sample</field>
<field name="model">sample.test</field>
<field name="arch" type="xml"
<tree string="Sample" default_order="name">
<field name="code" />
<field name="name" />
<field name="status" />
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_sample">
<field name="name">Sample</field>
<field name="res_model">sample.test</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click here to create a new sample Record.
</p>
</field>
</record>
Thanks in advance ..!
Please remove help from your defined action & check.

I am getting AssertionError: Element openerp has extra content: data, line 2

I am trying to install a module, then I am getting below error.
AssertionError: Element openerp has extra content: data, line 2
What type of mistake I did for getting this error.
In which file I have to search for error rectify. I am using odoo9.
Files:
This is my xmlfile.xml
<data>
<record model="ir.ui.view" id="10">
<field name="name">model.name</field>
<field name="model">smp.model2</field>
<field name="arch" type="xml">
<form>
<sheet>
<group colspan="4">
<group colspan="2" cal="2">
<field name="name"/>
<field name="active"/>
</group>
<group colspan="2" cal="2">
<field name="age"/>
<field name="sal"/>
</group>
<group colspan="2" cal="2">
<field name="adharid"/>
<field name="cell"/>
</group>
<notebook colspan="4">
<page string="extrainfo"><field name="extrainfo"/></page>
<page string="temporaryaddress"><field name="temporaryaddress"/></page>
<page string="perminantaddress"><field name="perminantaddress"/></page>
</notebook>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="20">
<field name="name">model.name</field>
<field name="model">smp.model2</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="active"/>
<field name="age"/>
<field name="sal"/>
<field name="adharid"/>
<field name="cell"/>
<field name="extrainfo"/>
<field name="temporaryaddress"/>
<field name="perminantaddress"/>
</tree>
</field>
</record>
<record model ="ir.actions.act_window" id="action_smp_model2">
<field name="name">sampmodel</field>
<field name="res_model">smp.model2</field>
<field name="view_type">form</field>
<field name="viwe_mode">tree,form</field>
</record>
<menuitem id="smp_main_menu1" name="smp model2"/>
<menuitem id="subsmp_main_menu1" name="Sub sample model"
parent="smp_main_menu1"/>
<menuitem id="actsmp_main_menu" name="action smp model"
parent="subsmp_main_menu1" action="action_smp_model2"/>
</data>
</openerp>
This is my data.xml file
<data>
<record id='1' name="smp.model2">
<filed name="name">name1</filed>
<filed name="age">23</filed>
<filed name="cell">123456434</filed>
</record>
<record id='2' name="smp.model2">
<filed name="name">name1</filed>
<filed name="age">23</filed>
<filed name="cell">123456434</filed>
</record>
<record id='3' name="smp.model2">
<filed name="name">name1</filed>
<filed name="age">23</filed>
<filed name="cell">123456434</filed>
</record>
</data>
</openerp>
This is python_file.py
from openerp import models,fields
class model2(models.Model):
_name="smp.model2"
name=fields.Char(string="model name", requred=True, help="name of the
model")
active=fields.Boolean(String="Active")
age=fields.Integer(string="person age",help="age of person")
sal=fields.Integer(string="sal")
adharid=fields.Integer(string="Adhar Id")
cell=fields.Integer(string="phone number",requred=True)
extrainfo=fields.Text(string="Extra information")
temporaryaddress=fields.Text(string="Temporary address")
perminantaddress=fields.Text(string="perminant address")
This is __openerp__.py file
{
'name':'module12',
'description':'module12',
'author':'naveen',
'version':'9.0',
'depends':['base'],
'data':['xmlfile.xml','data.xml']
}
you have errors in a xml, example:
requred=True is required=True
<filed is <field

How add new field on tree view (inherit on inherited)

I'm trying to replace a field in a tree view. Help me please.
This is script on base odoo enteprice
<record model="ir.ui.view" id="view_task_form2_inherited">
<field name="name">project.task.form.inherited</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2" />
<field name="arch" type="xml">
<field name="project_id" position="attributes">
<attribute name="on_change">onchange_project(project_id)</attribute>
</field>
<field name="tag_ids" position="after">
<field name="analytic_account_id" invisible="1"/>
<field name="progress" widget="progressbar"
groups="project.group_time_work_estimation_tasks"/>
</field>
<xpath expr="//notebook/page[#name='description_page']" position="after">
<page string="Timesheets" groups="project.group_tasks_work_on_tasks,project.group_time_work_estimation_tasks">
<field name="timesheet_ids" groups="project.group_tasks_work_on_tasks" context="{'default_account_id' : analytic_account_id, 'default_is_timesheet' : 1}">
<tree editable="top" string="Timesheet Activities">
<field name="date"/>
<field name="user_id" required="1"/>
<field name="name"/>
<field name="account_id"/>
<field name="unit_amount" string="Duration" sum="Total time" widget="float_time"/>
<field name="is_timesheet" invisible="1"/>
</tree>
</field>
<group>
<group class="oe_subtotal_footer oe_right" name="project_hours" groups="project.group_time_work_estimation_tasks">
<field name="effective_hours" widget="float_time" groups="project.group_time_work_estimation_tasks"/>
<field name="remaining_hours" widget="float_time" class="oe_subtotal_footer_separator" groups="project.group_time_work_estimation_tasks"/>
</group>
</group>
</page>
</xpath>
</field>
</record>
This is my custom script on _view.xml:
<record id="project_task_view_form" model="ir.ui.view">
<field name="name">project.task.view.form</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field name="arch" type="xml">
<xpath expr="/notebook/page[#name='description_page']" position="replace">
<page string="Timesheets" groups="project.group_tasks_work_on_tasks,project.group_time_work_estimation_tasks">
<field name="timesheet_ids" groups="project.group_tasks_work_on_tasks" context="{'default_account_id' : analytic_account_id, 'default_is_timesheet' : 1}">
<tree editable="top" string="Timesheet Activities">
<field name="date"/>
<field name="user_id" required="1"/>
<field name="name"/>
<field name="unit_amount" string="Duration" sum="Total time" widget="float_time"/>
<field name="is_timesheet" invisible="1"/>
<field name="invoiceable_analytic_line"/>
</tree>
</field>
</page>
</xpath>
</field>
</record>
I want add new field "invoiceable_analytic_line" inside "timesheet_ids", but it doesn't work.
anybody help me?
Thanks.
View
The procedure is correct but just that there is an error with the expr attribute inside xpath.
Instead:
<xpath expr="/notebook/page[#name='description_page']" position="replace">,you have to write:
<xpath expr="//sheet/notebook/page[1]" position="replace"> when on odoo 10<xpath expr="/sheet/notebook/page[#string='Description']" position="replace">Because description_page doesn't existSo copy whole <page string="Description">..</page> tag from /project/project_view.xml and paste it inside your xpath tag by modify the string. After that insert your field where you want
Model
class Add_in_timesheet(models.Model)
_inherit = 'project.task
invoiceable_analytic_line = fields.Char(string=u"Invoiceable")

Resources