Change CSS class to html table inside QWEB Report - Odoo 15 - odoo

If you have an element within a qweb report similar to this one
<table class="table table-sm o_main_table">
What should be the xpath to change the CSS class "table-sm" to "table-condensed" and get the following?
<table class="table table-condensed o_main_table">
Thank you!

You can use hasclass to search from a class like the below code:
<xpath expr="//table[hasclass('table-sm')]" position="attributes">
<attribute name="class">table table-condensed o_main_table </attribute>
</xpath>

Related

Having trouble with form inheritance in 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>

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

WARNING Error-prone use of #class

> WARNING 11_test1 odoo.addons.base.ir.ir_ui_view: Error-prone use of
> #class in view report_invoice_document
> (account_invoice_report.report_invoice_document): use the
> hasclass(*classes) function to filter elements by their classes
Can someone explain me why i'm getting this warning. using class only in 2 places.
<td class="text-right">
<span t-esc="', '.join(map(lambda x: (x.description or x.name), l.invoice_line_tax_ids))"/>
</td>
and
<xpath expr="//div[#class='row mt32 mb32']/div[#t-if='o.name']" position="replace"/>
You can use hasclass() now. Example-
In case of one class in the inherited path:
xpath expr="//div[hasclass('dropdown')]" position="replace">
In case of multiple class in inherited path:
xpath expr="//div[hasclass('dropdown','btn-group','dropdown_sorty_by')]" position="replace">
In your case it should be:
<xpath expr="//div[hasclass('row','mt32','mb32')]/div[#t-if='o.name']" position="replace"/>

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 to sum all the records and display as single in kanban view?

I need to sum the companies total and display as single row like in the image.
Now I just used the kanban view to display default view.
<kanban class="o_kanban_mobile">
<field name="name"/>
<field name="company"/>
<field name="actual_amount"/>
<field name="planned_amount"/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_card oe_kanban_global_click">
<table border="1" width="100%">
<tr>
<td rowspan="2"><t t-esc="record.name.value"/>-<t t-esc="record.company.value"/></td>
<td>Planned</td>
<td>Actual</td>
</tr>
<tr>
<td><t t-esc="record.planned_amount.value"/></td>
<td><t t-esc="record.actual_amount.value"/></td>
</tr>
</table>
</div>
</t>
</templates>
</kanban>
I think this will work for you.
Add a char field to your model don't show it . just define a defaut value for it, default = 'sum' then groub by that field.
You should get the same result.