Conditionally extend template with Odoo QWeb - odoo

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?

Related

Progressbar second sum field

I added a second sum field to the kanban progress bar view and it looks like the following.
Now I want to give the same format to the second view, instead of 24000, that shows 24k.
I’m using this code:
<templates>
<t t-inherit="web.KanbanView.ColumnProgressBar" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o_kanban_counter_side')]" position="after">
<![CDATA[ ]]>
<string name = "Bs"> Bs</string>
<t t-set="total" t-value="0"/>
<t t-foreach="widget.columnState.data" t-as="data_record">
<t t-set="total" t-value="total + data_record.data.expected_revenue_1"/>
</t>
<b class="mt-0">
<t t-esc="total"/>
</b>
</xpath>
</t>
</templates>
I tried using widget: ‘monetary’, also I read the odoo cookbook but can’t find anything that helps me

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.

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

How do I add a button with function to export the report as either .pdf,.xls or .csv formats in ODOO 8?

I am using odoo 8.0 and I'm making a report for asset list. So far I have created the asset list report:
How do I add a button with function to export the report as either .pdf,.xls or .csv formats?
Here is a snippet code I have for the report view.
<record model="ir.actions.act_window" id="action_fleet_reporting_asset_listing">
<field name="name">Asset Listing</field>
<field name="res_model">fleet.asset</field>
<field name="view_id" ref="fleet_asset_listing_report"></field>
<field name="view_type">tree</field>
<field name="view_mode">tree</field>
<field name="context">{"search_default_parent_false" : True,}</field>
<field name="help" type="html">
<p>
Odoo helps you managing the costs for your different vehicles
Costs are generally created from services and contract and appears here.
</p>
<p>
Thanks to the different filters, Odoo can only print the effective
costs, sort them by type and by vehicle.
</p>
</field>
</record>
<report id="report_fleet_asset_list"
name="fleet.qweb_fleet_asset_list"
model="fleet.asset"
string="Assets"
report_type="qweb-pdf" />
Then created the Template:
<?xml version="1.0" encoding="utf-8"?>
<!--Custom report.-->
<openerp>
<data>
<template id="qweb_fleet_asset_list">
<t t-call="report.html_container">
<t t-call="report.internal_layout">
<div class="page">
<h2>Aseet List</h2>
<div class="row mt4 mb4" t-as="o" t-foreach="docs">
<div class="col-md-6">
<t t-esc="o.name"/>
</div>
<div class="col-md-6">
<t t-esc="o.location" t-if="o.location"/>
<t t-if="not o.location">-</t>
</div>
</div>
</div>
</t>
</t>
</template>
</data>
</openerp>

Odoo - Change create button text

I am using Odoo 10e. In tree view or in form view for my particular model, i want to change the create button text to Add New User. How can we achieve this?
I tried to use Xpath for this, but as far as i know Xpath is use to inherit from a view and add something in the view not to change the item in the parent view
Create one xml file and write this below code in it.
For listview and formview it will change the name of create button as per your custom string.
Add this xml file path to qweb section in manifest file.
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="ListView.buttons">
<t t-jquery=".o_list_button_add" t-operation="replace">
<button type="button" class="btn btn-primary btn-sm o_list_button_add" accesskey="c">
<t t-if="widget.model === 'sale.order'">
Your String
</t>
<t t-if="widget.model !== 'sale.order'">
<t t-esc="widget.options.addable"/>
</t>
</button>
</t>
</t>
<t t-extend="FormView.buttons">
<t t-jquery=".o_form_button_create" t-operation="replace">
<button t-if="widget.is_action_enabled('create')" type="button"
class="btn btn-default btn-sm o_form_button_create" accesskey="c">
<t t-if="widget.model === 'sale.order'">
Your String
</t>
<t t-if="widget.model !== 'sale.order'">
Create
</t>
</button>
</t>
</t>
</templates>
I hope this answer will help you.
Simply just xpath to that button.
Then give position replace and change the string to Add New User from Create.
Try the code like this.
But remember the name of the button will be as it is.
Thanks
<xpath expr="//button[#name='action_set_create']" position="replace">
<button name="action_set_create" string="Add New User"/>
</xpath>