Odoo - hide / modify / append on generated fields - odoo

There are fields like campaign_id which i would like to hide, or append some other fields after them:
But all my expression get fully ignored:
like...
<xpath expr="//field[#name='campaign_id']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
...or...
<field name="campaign_id" invisible="1" />
Other expressions in the same xml file will be correctly evaluated.
There are no errors printed or shown.
This is the inherid_id and more:
<odoo>
<record id="crm_lead_view_form" model="ir.ui.view">
<field name="name">crm.lead.inherit.view.form</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_lead_view_form"/>
<field name="arch" type="xml">
Dont know if it's related: It seems that the campaign_id field is an merged field from crm_lead.py.
Maybe someone can lift the (for me) unknown 'magic' which prevents edit / hide / append after / ... the merged field campaign_id?

Odoo has one formular view for leads and opportunities. Lots of fields are defined twice in the view, that's why your code is working without errors. But using XPath (your first approach) or changing something by node names (your second approach) only changes the "first" found target. And the first found target is for the "lead's view".
You can see it here
A simplified example:
<page name="extra" string="Extra Info" attrs="{'invisible': [('type', '=', 'opportunity')]}">
<group>
<group string="Tracking" name="categorization">
<field name="campaign_id" />
<field name="medium_id"/>
<field name="source_id"/>
</group>
</group>
</page>
<page name="lead" string="Extra Information" attrs="{'invisible': [('type', '=', 'lead')]}">
<group>
<group string="Marketing">
<field name="campaign_id" />
<field name="medium_id" />
<field name="source_id" />
</group>
</group>
</page>
So if you want to hide one or both fields, you have to use XPath twice or you could also mix it up. But i would prefer using XPath twice, because it's more comprehensible.
<xpath expr="//page[#name='extra']//field[#name='campaign_id']" position="attributes">...</xpath>
<xpath expr="//page[#name='lead']//field[#name='campaign_id']" position="attributes">...</xpath>

Related

Empty list view (new module on odoo 12)

I have made a new module, everything seems to be ok (i can CRUD product), but list of products is empty.
What can cause such trouble? Something wrong with
<!-- Action to open list -->
<act_window id="action_for_menu"
name="List of products"
res_model="x.x"
view_type="form"
view_mode="tree,form" />
<!-- List view. -->
<record id="x_list_view" model="ir.ui.view">
<field name="name">x.list</field>
<field name="model">x.x</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="descr"/>
</tree>
</field>
</record>
The reason of my trouble was in field "active", which i made default=False. The active field is used to inactivate records, and by default only active records will be shown.

Odoo 10: Add extra fields to the product form

I want to add a couple of extra fields to the product form, right after 'standard_price'.
I created a view that inherits from "product.product_template_form_view" and added my fields there:
<field name="standard_price" position="after">
<field name="my_field" />
</field>
I then restart odoo updating the module, but I don't see my new fields when I call the product form.
The fields appear on the database model (created inherited models also), but not on the user interface.
What I'm missing here?
Check these things:
Inherited from correct base form product.template.common.form
Make sure you are looking at correct form for product.template (Product), not product.product (Product Variant).
Do you see the input field without caption in edit mode? If this is the case, you can have broken structure in the html level. Next bullet will solve this.
Standard_price field has unique html structure because it can have unit of measure (uom) connected to it. Try connecting to simple field or use the container div standard_price_uom for connection, see template code below.
Template code for working view with a new field after standard_price_uom div:
<div name='standard_price_uom' position="after">
<field name="my_field" />
</div>
If these does not help, please provide whole view definition.
Make sure you use the correct model. Use product.template instead of product.product.
<record id="product_template_form" model ="ir.ui.view">
<field name="name">product.template.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<field name="standard_price" position="after">
<field name="my_field"/>
</field>
</field>
</record>
...
class ProductTemplate(models.Model):
_inherit = "product.template"
my_field = fields.Char()
Make sure you have added your XML file into your module’s __manifest__.py file. Odoo only pulls in XML from files that you tell it to.
You can see examples of this on any core modules. See sale/__manifest__.py for an example.
On your module, it would be something like this:
{
...
‘data’: [
‘views/form/form_product.xml’,
]
...
}
I have tested it in Odoo 12.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_product_template_common_form_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//div[#name='standard_price_uom']" position="after">
<label for="my_field" string="My Field"/>
<div>
<field name="my_field"/>
</div>
</xpath>
</field>
</record>
</odoo>

Odoo 10 - QWeb hide a view element if a field is False

I have following QWeb element:
<record id="extended_res_partner" model="ir.ui.view">
<field name="name">Extended View</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<notebook position="inside">
<page string="Foo" name="foo" attrs="{'invisible': [('is_customer', '=', False),]}">
<field name="is_customer" invisible="1"/>
<span>Foo2</span>
</page>
</notebook>
</field>
</record>
But it does not work. I get:
Field `is_customer` does not exist
If I remove attrs=... it works fine.
Even that you didn't provide the error message but this will work only if the the form view if for res.partner but i'm assuming that the form is for another model that have a many2one relation with res.partner in this case you need to create a related field in the model.
partner_id = ......
is_customer = fields.Boolean(related='partner_id.is_customer', readonly=True)
Then you need to add this field to the form view because attrs is client side feature it need the value in form in order to work.
<page string="foo" name="foo" attrs="{'invisible': [('is_customer', '=', False),]}">
<field name="is_customer" invisible="1"/>
<span>Foo2</span>
</page>
Note: if the form view is for res.partner just add the field to the form view because as I said is a client side operation it will not call the server to know what is the value of that field you need to pass it.

proper way to replace view form

I need to override account.account_aged_balance_view in order to hide a field (Period Length (days)) as well add new field in the same time.
I tried the following in my custom module view:
<openerp>
<data>
<record id="account_aged_balance_view" model="ir.ui.view">
<field name="name">Aged Partner Balance</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<form string="Report Options">
<separator string="Aged Partner Balance"/>
<label string="Dariel Partner Balance is a more detailed report of your receivables by intervals. When opening that report, Odoo asks for the name of the company, the Start Date and the size of the interval to be analyzed (in days). Odoo then calculates a table of credit balance by start Date. So if you request an interval of 30 days Odoo generates an analysis of creditors for the past month, past two months, and so on. "/>
<group col="4">
<field name="date_from"/>
<newline/>
<field name="result_selection" widget="radio"/>
<field name="target_move" widget="radio"/>
</group>
<field name="journal_ids" required="0" invisible="1"/>
</form>
</field>
</record>
</data>
</openerp>
those XML appended to the modal form instead of replacing the original form, like shown in the image.
so, am I doing it right (ofcourse it's not right) or how the proper way of doing it?
You can both replace the whole form view or remove and add only the fields you want. You have to use the xpath to do that.
To replace the whole view:
<record id="account_aged_balance_view" model="ir.ui.view">
<field name="name">Aged Partner Balance</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<xpath expr='//form' position='replace'>
< your form view >
</xpath>
</field>
</record>
Or you can remove only what you don't want and add what you want with:
<record id="account_aged_balance_view" model="ir.ui.view">
<field name="name">Aged Partner Balance</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<xpath expr='//field[#name="period_length"]' position='replace'/>
<xpath expr='//field[#name=" < name of the field you want to put yours after > "]' position='after'>
<field name=' < your field name > '/>
</xpath>
</field>
</record>
I did not try it, but it should work.

How to hide fields based on condition in odoo?

I have created few custom fields for products.Products appear in sales,purchase,warehouse and manufacturing module.I want to make my custom fields appear only in manufacturing module and hide everywhere else.So how to put condition on invisible attribute.I tried like this and got error as Unknown field _name in domain
attrs="{'invisible': [('_name', '!=', 'mrp.bom')]}"
Python file,
from openerp import fields,models, api
class product_template(models.Model):
_inherit = "product.template"
rim_weight = fields.Float(string='Rim Weight(KG)', readonly=True, compute='_compute_one_rim_weight')
width = fields.Float(string='Width(cm)',default='50')
length = fields.Float(string='Length(cm)',default='63')
gsm = fields.Float(string='Gram per square meter(gsm)',default='230')
Xml file,
<record id="product_template_form_view_dis_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.dis.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[#string='Accounting']" position='after'>
<page string='Cover Page Paper'>
<group>
<field name="width"/>
<field name="length"/>
<field name="gsm"/>
<field name="rim_weight"/>
</group>
</page>
</xpath>
</field>
</record>
There are many ways to do this, however I suggest following options to you.
Modify an existing action and set context inside that and based on that context just write condition in view. (Remember here you need to override an action, and if you want to create another then you need to redefine menu to assign new action to that menu).
Create new view and set this view reference in an action of that model in which you want to show these fields. In new view you need to visible those fields, no need to extend product template existing view.
However the 1st solution is easy to achieve and 2nd one is lengthy.
Example of 1st solution:
<record id="action_name" model="ir.actions.act_window">
<field name="name">Name</field>
<field name="res_model">product.template</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context" eval="{'is_manufacturing_model':True}" />
</record>
And then in view just write like this
<page string='Cover Page Paper'>
<group invisible="context.get('is_manufacturing_model',False)">
<field name="width"/>
<field name="length"/>
<field name="gsm"/>
<field name="rim_weight"/>
<group>
</page>