Odoo testing failed to initialize database - odoo

I was testing Odoo modules, using coverage command, I get the Failed to initialize database error, I think the error is in this line:
expr="//field[#name='unit_amount']", but i don't know how to solve it.
<record id="hr_timesheet_sheet_form_inherited_working_type" model="ir.ui.view">
<field name="name">hr.timesheet.sheet.form.inherited.working_type</field>
<field name="model">hr_timesheet_sheet.sheet</field>
<field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='unit_amount']" position="before">
<field name="task_id" domain="[('project_id','=',project_id)]" attrs="{'required':True}"/>
<field name="working_type_id"/>
</xpath>
</field>
</record>
Thanks for your help

Your xpath is wrong. The field you are using is in timesheet line and not in the timesheet.
Use following xpath:
<xpath expr="//field[#name='timesheet_ids']/tree/field[#name='unit_amount']" position="before"></xpath>

Related

How to show out more fields of Employee in Odoo 13 Enterprise?

Currently, The employee module just show out with 3 fields: Job title, Work Mobile and Work Email.
So how to show out more details with more fields of an Employee?
Thank you!
You have to extend hr employees kanban view.
You may try following code:
<record id="hr_kanban_view_employees" model="ir.ui.view">
<field name="name">hr.employee.kanban</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.hr_kanban_view_employees"/>
<field name="arch" type="xml">
<xpath expr="//div[hasclass('oe_kanban_details')]" position="inside">
<field name="passport_id"/>
<field name="FIELD_NAME"/>
</xpath>
</field>
</record>

Issue when Invisible Sale Order line Description Field

Currently, I'm working on odoo version 12.0.
I'm facing the issue, When I invisible sale order line Description field from Tree view at that time it also invisible the section text & Note Text.
Code for invisible sale order line Description field:
<xpath expr="//page[#name='order_lines']//tree/field[#name='name']" position="attributes">
<attribute name="invisible">1</attribute> ​
​</xpath>
Can anyone help me to resolve this issue?
Thanks in advance.
Technically Description, section text and note text is same field='name' in sale.order.line at client-side UI tweak based on field display_type
you should try attrs invisible based on display_type instead of invisible=1
ref:
https://github.com/odoo/odoo/blob/12.0/addons/sale/models/sale.py#L1223
Please use the below code
<record id="view_order_form_inherit_custom" model="ir.ui.view">
<field name="name">sale.order.form.custom</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='order_line']/tree/field[#name='name']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</field>
</record>

Hide group in odoo 9

How with xpath expr replace (hide) group Configuration in project managment module in tabs settings?
<group string="Configuration" groups="base.group_no_one">
<field name="sequence" groups="base.group_no_one"/>
</group>
I'm try with below code but get error:
<xpath expr="//group[#string='Configuration']" position="replace">
</xpath>
I guess the error you are getting is a ParseError, because you are using the string attribute as a selector inside your XPath expression, which is not allowed since Odoo v9.0.
Instead, you might try to find the sequence field and the select the parent:
<xpath expr="//field[#name='sequence']/.." position="replace">
</xpath>
However, replacing the whole element might not be the best solution, because other modules might use the group or the sequence field inside an inherited view, which would cause an error. A better solution would be to hide the group using the invisible attribute. The full record could look something like this:
<record id="edit_project_inherit" model="ir.ui.view">
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='sequence']/.." position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</field>
</record>

Odoo tree view with create_date

Do you know how to insert the column create_date on the Odoo Customers Tree View? It would let me see the most recent clients created on the system.
Thank you,
Eduardo
for insert the column create_date on the Odoo Customers Tree View follow the following steps:-
1:- inherit in .py file
from openerp import models, fields, api, _
class ResPartner(models.Model):
_inherit = 'res.partner'
create_date = fields.Datetime("Date")
2:- extend res.partner tree view.
<record id="view_inherit_res_partner_tree" model="ir.ui.view">
<field name="name">res.partner</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='function']" position="before">
<field name="create_date"/>
</xpath>
</field>
</record>
I would advise against changing the _order attribute on the model as that changes the order in the database, which may not be what you are trying to achieve. Instead, add a default_order="create_date desc" attribute to the tree element of the list view. In the arch:
<tree position="attributes">
<attribute name="default_order">create_date desc</attribute>
</tree>
Follow this step
1/ Inherit res_partner class.
In your .py file, add this code.[redefine _order attribute]
class res_partner(osv.Model):
_inherit = "res.partner"
_order = "create_date desc"
res_partner()
2/ In your view file, inherit the partner's tree-view and add create_date field.
<record id="view_partner_tree_extended" model="ir.ui.view">
<field name="name">res.partner.extended</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='display_name']" position="before">
<field name="create_date"/>
</xpath>
</field>
</record>
Note : No need to add create_date field in python file because it comes from osv.model base class.
_order atttribute is used for sort the records as your requirement.
Restart server and update your module.
Hope It will work for you !!
Let me know if you have any query.
As create_date is Automatic fields in Odoo, you can directly access it in the tree view.
Example:-
<record id="customer_list_view" model="ir.ui.view">
<field name="name">customer.tree</field>
<field name="model">bank.customer</field>
<field name="arch" type="xml">
<tree string="Customer View">
<field name="name"/>
<field name="contact"/>
<field name="create_date"/> // Directly access from database(no need to declare in model)
</tree>
</field>
</record>
I'd suggest that you'll use xpath and inherit the tree view from the customers. The following xml should work:
<record id="inherit_customer_tree_view" model="ir.ui.view">
<field name="name">res.partner.tree.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree" />
<field name="arch" type="xml">
<xpath expr="//field[#name='display_name']" position="before">
<field name="create_date" />
</xpath>
</field>
</record>
To insert create_date into the tree view
first create a field with the same name ['create_date'] in your .py file
'create_date':fields.datetime('Create Date')
then put it in your tree view. It will work.
Write code in your specific tree view
<record id="my_tree_view_id" model="ir.ui.view">
<field name="name">my.mode.view.tree</field>
<field name="model">my.model</field>
<field name="mode">primary</field>
<field name="arch" type="xml">
<tree string="My model tree view">
<field name="name" />
<field name="product_count" />
<field name="write_date" />
</tree>
</field>
</record>
Using the write_date in field tag then print date with time in specific tree view.
you can direct declare in xml. No need to define .py file. Because create_date is a odoo magic field. so, you can declare directly in tree view.
<data>
<xpath expr="//field[#name='display_name'][not(ancestor::field)]" position="after">
<field name="create_date"/>
</xpath>
<xpath expr="//field[#name='create_date'][not(ancestor::field)]" position="after">
<field name="create_uid"/>
</xpath>
</data>
Place this code in a view using the developers tool button in the partner tree
create_date = date
create_uid = the user that created the partner
In Odoo/OpenERP we can inherit or use existing modules object/class/model and views. We can also inherit single field of existing modules. The question is why we need such inheritance.
The purpose of inheritance or why we need inheritance is given below:
To change attributes of some fields which exists on existing/custom
model (e.g. making fields readonly,invisible)
To add/modify/delete old or new fields in existing/custom model
(e.g. Product, Sales, HR, Fleet Management, Attendance modules model
etc)
We can also add buttons in already existing/custom model (form and
tree) view by using inheritance

Branch wise Division in CRM module in Openerp

For a company there can be different branches across the country. In Openerp,in CRM module Can i filter the Leads by Branches(here filter should be branch name) of that company.Thanks in advance.
My Code
lead.py
'branch_name':fields.selection([('Ahmedabad','Ahmedabad'),('Bangalore','Bangalore'),('Chennai','Chennai'),('Hyderabad','Hyderabad'),('Koltata','Koltata'),('Mumbai','Mumbai'),('NewDelhi','New Delhi'),('Pune','Pune')],'Branch'),
lead_view.xml
<record id="lead_view_crm_case_leads_filter" model="ir.ui.view">
<field name="name">CRM - Leads Search</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.view_crm_case_leads_filter" />
<field name="arch" type="xml">
<search string="Search Leads">
<field name="branch_name" filter_domain="[('branch_name','ilike',self)]"/>
</search>
</field>
</record>
added and new field branch in crm.lead. inherit search view added this field in filter
it will help you