Odoo 10 change field colour - odoo

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

Related

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.

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.

Reach field in invoice report

I need to extend invoice report with field note. but I'm getting error that field does not exist. I'm stuck and don't know how to reach that field. did tried with partner_id.note too but also getting error.
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_invoice_document" inherit_id="account.report_invoice_document">
<xpath expr="//div[#class='page']/*[last()]" position="after">
<div class="row">
<div class="col-xs-6">
<span t-esc="o.note"/><br/>
<div class="left_sign_block">
<span>Note</span>
</div>
</div>
</div>
</xpath>
</template>
</data>
</openerp>
class AccountInvoiceTax(models.Model):
_inherit = 'account.invoice.tax'
note = fields.Text(related='tax_id.note', string='Note')
QWebException: "'account.invoice' object has no attribute 'note'" while evaluating 'o.note'
You have extended the model account.invoice.tax and not account.invoice. The error message is correct. So either you extend invoice or you have to use note from the invoice tax lines (tax_line_ids).

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?

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>