WARNING Error-prone use of #class - odoo

> 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"/>

Related

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

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>

How do I migrate a module to remove a custom `res.config.settings` field?

Suppose I have a module which defines some custom res.config.settings fields like so:
from odoo import models, fields
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
custom_field = fields.Char(config_parameter="custom.field")
some_other_custom_field = fields.Char(config_parameter="some.other.custom.field")
And then in my XML I have something like this:
<odoo>
<record id="custom_settings_view_form" model="ir.ui.view">
<field name="name">custom.settings.view.form</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="custom_base_settings_view_form"/>
<field name="arch" type="xml">
<div data-string="custom" position="inside">
<h2>Custom</h2>
<div class="row mt16 o_settings_container">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<label for="custom_field"/>
<div class="text-muted">Description...</div>
<div class="content-group">
<div class="mt16">
<field name="custom_field"
placeholder="Placeholder..."/>
</div>
</div>
</div>
<div class="o_setting_right_pane">
<label for="some_other_custom_field"/>
<div class="text-muted">Description...</div>
<div class="content-group">
<div class="mt16">
<field name="some_other_custom_field"
placeholder="Placeholder..."/>
</div>
</div>
</div>
</div>
</div>
</div>
</field>
</record>
</odoo>
Suppose that now later I've implemented some new functionality elsewhere that eliminates my need for custom_field. As such, I'd like to remove it entirely. However, as you can see, the custom_settings_view_form also includes some_other_custom_field, which I need to keep. This means that my options are limited:
I cannot just remove the ir.ui.view record, because then I would lose the UI for some_other_custom_field.
I also cannot just uninstall and then install the module again, because it would result in data loss elsewhere.
So specifically I want to remove the following line from my model:
custom_field = fields.Char(config_parameter="custom.field")
And the following block from my XML:
<div class="o_setting_right_pane">
<label for="custom_field"/>
<div class="text-muted">Description...</div>
<div class="content-group">
<div class="mt16">
<field name="custom_field"
placeholder="Placeholder..."/>
</div>
</div>
</div>
However, when I remove that code and then run my Odoo server again with -u <name_of_containing_module>, I get the following error:
odoo.tools.convert.ParseError: "Error while validating view
Field `custom_field` does not exist
Error context:
View `custom.settings.view.form`
[view_id: <id>, xml_id: <name_of_containing_module>.custom_settings_view_form, model: res.config.settings, parent_id: <parent_id>]
...
I just learned that I can create scripts at <module_root>/migrations/<version>/ to help with this sort of situation, but I have no idea what I would need to put in my migration script to deal with this issue. How can I remove fields and modify views in a module without causing errors and without requiring that the module be reinstalled?
You could try this steps:
Remove custom_field from XML view and change the actual id
custom_settings_view_form.
Update your module, that shouldn't produce any error and you won't see custom_field any more.
At this moment you could deside ignore custom_field, nothing will happend. Any way if you are a person that don't like death code inside his project like me, you can continue with the next steps.
Remove custom_field definition for .py file.
Update your module.
If you have the same error reported, you sould execute the 3.1 step bellow.
3.1. Clean the database data for custom_field. By SQL. Continue with 4 and 5 steps.
Please share your comments of the execution of these steps.
I hope this answer can be helpful for you.

how to give Odoo xpath in t-attf-id

How to give xpath in this position inside.
<div t-attf-id="o_payment_form_acq_{{acq.id}}" t-attf-class="hidden {{'panel-footer' if acq.save_token == 'ask' else ''}}">
I tried the following but it gives an error:
<template id="stripe_form_type" inherit_id="payment.payment_tokens_list">
<xpath expr="//div[hasid('o_payment_form_acq_{{acq.id}}')]" position="after">
<div>hello</div>
</xpath>
</template>
Maybe try
<template id="stripe_form_type" inherit_id="payment.payment_tokens_list">
<xpath expr="//div[#t-attf-id='o_payment_form_acq_{{acq.id}}']" position="after">
<div>hello</div>
</xpath>
</template>
When it is hard to get element I use relative path. The element you want to get contains inout element.
<div t-attf-id="o_payment_form_acq_{{acq.id}}" t-attf-class="hidden {{'panel-footer' if acq.save_token == 'ask' else ''}}">
<label t-if="acq.save_token == 'ask'"><input type="checkbox" name="o_payment_form_save_token" data-remove-me=""/> Save my payment data</label>
</div>
So you can get it using this code
<template id="stripe_form_type" inherit_id="payment.payment_tokens_list">
<xpath expr="//input[#name='o_payment_form_save_token']/.." position="after">
<div>hello</div>
</xpath>
</template>

Add custom text in qweb report odoo9

How add custom text in inherit qweb?
For example in Sale/view/report_saleorder.xml
below class="oe_structure" i need one table
<p t-field="doc.note" />
<p t-if="doc.payment_term_id.note">
<span t-field="doc.payment_term_id.note"/>
</p>
<p t-if="not doc.payment_term_id and doc.partner_id.property_payment_term_id">
<span t-field="doc.partner_id.property_payment_term_id.note"/>
</p>
<p id="fiscal_position_remark" t-if="doc.fiscal_position_id and doc.fiscal_position_id.note">
<strong>Fiscal Position Remark:</strong>
<span t-field="doc.fiscal_position_id.note"/>
</p>
<div class="oe_structure"/>
<xpath expr="???" position="???">
<table><tr><td>CUSTOM TEXT</td></tr></table>
</xpath>
I am not sure if the above xml is the whole report however you could use something like this.
<xpath expr="//div[#class='oe_structure'][last()]" position="after">
<!-- YOUR TABLE HERE -->
</xpath>
This assumes this is the last instance of oe_structure in the xml you are inheriting from.

Conditionally extend template with Odoo QWeb

I added a boolean field to my stock.picking.type model called x_is_dropship_aggregate_picking_type. This field is False for all picking types in my database except for one.
I am trying to make some changes to the Kanban card for the picking type that has x_is_dropship_aggregate_picking_type == true, but I can't seem to get it to work.
Here's my template created through the Odoo V10 UI. It inherits from the stock.picking.type.kanban view:
<?xml version="1.0"?>
<data>
<xpath expr="//field[#name='count_picking_backorders']" position="after">
<field name="x_is_dropship_aggregate_picking_type"/>
</xpath>
<templates>
<t t-extend="kanban-box">
<t t-if="record.x_is_dropship_aggregate_picking_type.raw_value" t-jquery="button" t-operation="replace">
<button class="btn btn-primary">
<span>100 To Receive</span>
</button>
</t>
</t>
</templates>
</data>
As you can see on this line:
<t t-if="record.x_is_dropship_aggregate_picking_type.raw_value" t-jquery="button" t-operation="replace">
I am attempting to only alter the parent template if the value of this field is true. Unfortunately, every Kanban card within the view is getting changed, not just the one I want. It seems that t-if and t-jquery do not working together in that way.
Is there any way to conditionally alter this view and leave it unchanged otherwise?