Having trouble with form inheritance in Odoo - odoo

I've been raking my head around this for the better part of the day and i just can't seem to get it right.
I'm trying to add a new field to the res_users form but whatever I do it just won't show. No errors, everything seems normal but the field just isn't showing in the form.
manifest.py:
{
'name': "Extended User",
'version': '1.0',
'depends': ['base'],
'author': "blake_won",
'category': 'custom',
'description': """
Description text
""",
# data files always loaded at installation
'data': [
'views/extended_views.xml',
],
}
views file:
<odoo>
<record id="res_users_form_view" model="ir.ui.view">
<field name="name">res.users.form.inherit</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='partner_id']" position="after">
<group>
<field name="extended_variable"></field>
</group>
</xpath>
</field>
</record>
</odoo>
extendeduser.py:
from odoo import models, fields
class extendedUser(models.Model):
_inherit = 'res.users'
extended_variable = fields.Char(string="EXTENDED VARIABLE",default="NA")
console log:
2021-09-08 15:35:14,386 55731 INFO mydb odoo.modules.loading: Loading module extended_user (2/8)
2021-09-08 15:35:14,411 55731 INFO mydb odoo.modules.registry: module extended_user: creating or updating database tables
2021-09-08 15:35:14,484 55731 INFO mydb odoo.modules.loading: loading extended_user/views/extended_views.xml```
Please help me, i'm at my wit's end

As you can read in the documentation:
An xpath element with an expr attribute. expr is an XPath expression2 applied to the current arch, the first node it finds is the match
Odoo will find the first partner_id field, which is before the image field, and the div containing that field will be invisible if the current user and its related partner are active.
If you check the page source code, you will find after a hyperlink named partner_id something similar to:
<table class="o_group o_inner_group">
<tbody>
<tr>
<td class="o_td_label">
<label class="o_form_label" for="o_field_input_710" data-original-title="" title="">EXTENDED VARIABLE</label>
</td>
<td style="width: 100%;">
<span class="o_field_char o_field_widget" name="extended_variable">NA</span>
</td>
</tr>
</tbody>
</table>
Which is the rendered group
You can try to match the second partner_id field, which is inside a group inside a div that has a class named oe_title.
<xpath expr="//div[hasclass('oe_title')]/group/field[#name='partner_id']" position="after">
<field name="extended_variable"/>
</xpath>

Related

add checkbox field on product page on odoo

i added a checkbox on product page
When (checkbox_customtext) field is TRUE a (customtext) field should appear on the site
When an False field should disappear
I wrote the code but does not work
Please help me solve the problem
py xml files
<odoo>
<template id="website_insert_customtext" inherit_id="website_sale.address">
<xpath expr="//div[#id='div_phone']" position="after">
<!--hier is not working-->
<figure t-foreach="product_template" t-as="o" t-if="o.checkbox_customtext == True" class="snip1533">
<div t-attf-class="form-group #{error.get('customtext') and 'has-error' or ''} col-md-6"
id="div_custom_text">
<label class="control-label" for="customtext">Custom Text ( Only For Tactical vest )</label>
<input name="customtext" class="form-control"
t-att-value="'customtext' in checkout and checkout['customtext']"/>
</div>
</figure>
</xpath>
</template>
by .py
from odoo import models, fields
class ProductTemplate(models.Model):
_inherit = 'product.template'
checkbox_customtext = fields.Boolean('Add Custom field', default=True, )
class ResPartner(models.Model):
_inherit = 'sale.order'
customtext = fields.Char('Custom Text')
You can do it without using template. Just add to your customtext field in xml attrs="{'invisible': #your_domain}" and it will do the job.
<field name="customtext" attrs="{'invisible':[('checkbox_customtext', '=', False)]}"/>

Odoo 10 change field colour

I am trying to change the color of a field in Odoo10. here is my code
<xpath expr="//field[#name='order_line']/form//field[#name='analytic_tag_ids']" position="after">
<label for="squarebox"/>
<div>
<field name="squarebox"/>
</div>
<label for="squaremtrsold"/>
<div>
<field name="squaremtrsold"/>
</div>
</xpath>
I tried <field name="squarebox"style="background:Blue;"/>
But this did not work?
Try adding the style for the div containing the field definition, since the field tag will not appear on the final html.
You could also add a class to the containing div and with some CSS rules you could target the field dom nodes to add the proper style rules
Try this module https://apps.odoo.com/apps/modules/10.0/web_widget_color_field/
using above module widget you can change the filed colour as per your interest.
You can give it a class, for instance 'squarebox', and then write your css code in your static folder, taking into account that your field will be rendered as an input tag later. So the next code should do the trick.
<label for="squarebox"/>
<div>
<field name="squarebox" class="squarebox"/>
</div>
And then in your css file:
input.squarebox {
background-color: blue;
}
Pay attention to append your custom css to the assets, something like this:
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="assets_backend" name="My Module Assets" inherit_id="web.assets_backend">
<xpath expr="//link[last()]" position="after">
<link rel="stylesheet" href="your_module_name/static/src/css/styles.css"/>
</xpath>
</template>
</odoo>
And finally to the manifest.py
'data': [
'views/your_custom_assets.xml',
],
'css': ['static/src/css/styles.css'],
You should upgrade your modulea, and if not working, enter in ?debug=assets mode

I want to print the values of the 'tag (tag_ids)' in the report of 'chart of accounts.'

I am working on the accounts report where i need to print the Tags (which is a many2many widget) in the report of Trial Balance under the option- Chart of Accounts
Image of the section-
I was successful in adding the field of Tags in the report as shown below-
Problem :-
The problem which i'm facing is that i am not able to bring the values of tags over the report under the tags.
Code :-
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- Trial Balance Tag print -->
<template id="report_trialbalance" inherit_id="account.report_trialbalance">
<xpath expr="//table[#class='table table-condensed']//thead//tr//th" position="after">
<th>Tags</th>
</xpath>
<xpath expr="//table[#class='table table-condensed']//tbody//tr//td" position="after">
<td t-foreach="Accounts" t-as="account">
<span t-att-style="style" t-esc="account['tag_ids']" t-options="{'widget': 'many2many_tags'}" />
</td>
</xpath>
</template>
</data>
</odoo>
Please if anyone could help me out on bringing the values of tag in report,
Thanks in advance.

How can I add a header to a form that has already been defined in Odoo?

Is it possible to inherit a form view and add a header to it? I've tried:
<field name="arch" type="xml">
<xpath expr="//form" position="before">
<header>
<h1>hi</h1>
</header>
</xpath>
</field>
and
<form position="inside">
<header>
<h1>hi</h1>
</header>
</form>
What can I do? I want to add buttons to the form in a nice manner without needing to redefine the whole form.
<xpath expr="/form/*" position="before">
<header>
<h1>hi</h1>
</header>
</xpath>
Note that this requires for the parent form to not be empty.
This will take the current header and then replace it by the header you'll define here.
<xpath expr="//form/header" position="replace">
<header>
<h1>hi</h1>
</header>
</xpath>

Kanban view in OpenERP

How do I create a kanban view in OpenERP?
The developer book doesn't seem to have any information on the new kanban view, and I didn't see anything useful in the OpenERP forum.
Here is sample code showing how to develop a kanban view in OpenERP.
For the kanban view you have to prepare 2 files: (1)xml file and (2) css file. The CSS file is used for the formating of the kanban view.
<record model="ir.ui.view" id="resource_kanban_view">
<field name="name">any name of ur model</field>
<field name="model">object.name</field>
<field name="type">kanban</field>
<field name="arch" type="xml">
<kanban>
<templates>
<t t-name="kanban-box">
<div class="oe_resource_vignette">
<div class="oe_resource_image">
<a type="edit"><img t-att-src="kanban_image('object.name', 'photo', record.id.value)" class="oe_resource_picture"/></a>
</div>
<div class="oe_resource_details">
<ul>
<!--Here you have to write the object's field name which you want to display in kanban view -->
<li><field name="name"/></li>
<li><field name="author"/></li>
<li><field name="description"/></li>
<li><field name="available_copy"/> </li>
</ul>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
Their is Doc on this, KANBAN view is created based on QWEB technology, developed by OF itself, you can see the the whole lib QWEB lib and under Doc Section you can see how you can define the qWeb QWEB Template, Now if you understand it then all you just need to do is out your web template under tag in view declaration, where other systex is same as generic view declaration :
<record model="ir.ui.view" id="view_external_id">
<field name="name">View Name</field>
<field name="model">openerp.modelfield>
<field name="type">kanban</field>
<field name="arch" type="xml">
<kanban>
<field name="color"/>
<!--list of field to be loaded -->
<field name="list_price"/>
<templates>
<!--Your Qweb based template goes here, each record will be wrapped in template so you can arrange field veyr easily in box -->
</templates>
</kanban>
</field>
</record>
Hope this will help you.
Regards
I can't see any documentation for it yet, so the best you can do is look for examples in the addons project. Search all the XML files for <kanban>. Here's an example from the stock module:
<record model="ir.ui.view" id="product.product_kanban_view">
<field name="name">Product Kanban</field>
<field name="model">product.product</field>
<field name="type">kanban</field>
<field name="arch" type="xml">
<kanban>
<field name="color"/>
<field name="type"/>
<field name="product_image"/>
<field name="list_price"/>
<templates>
<t t-name="kanban-box">
<div class="oe_product_vignette">
<div class="oe_product_img">
<a type="edit"><img t-att-src="kanban_image('product.product', 'product_image', record.id.value)" class="oe_product_photo"/></a>
</div>
<div class="oe_product_desc">
<h4><a type="edit"><field name="name"></field></a></h4>
<ul>
<li t-if="record.type.raw_value != 'service'">Stock on hand: <field name="qty_available"/> <field name="uom_id"/></li>
<li t-if="record.type.raw_value != 'service'">Stock available: <field name="virtual_available"/> <field name="uom_id"/></li>
<li>Price: <field name="lst_price"></field></li>
<li>Cost: <field name="standard_price"></field></li>
</ul>
</div>
</div>
<script>
$('.oe_product_photo').load(function() { if($(this).width() > $(this).height()) { $(this).addClass('oe_product_photo_wide') } });
</script>
<div></div>
</t>
</templates>
</kanban>
</field>
</record>
Simply in xml file update this model="ir.actions.act_window" with view_mode like:
<record id="action_id" model="ir.actions.act_window">
<field name="name">Name1</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">model_name</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form,calendar,graph,gantt</field>
.....
</record>
This is the way how to call all view, and link http://www.slideshare.net/openobject/openerp-61-framework-changes will help u how to create kanban view.
I hope it will help you...