Change record color on Kanban view Odoo 14 - odoo

I need help, I want to color the record in the CRM kanban view in red if my date field date_operation is less than current_date. I write this xml code but nothing happens.
N.B : I have created a date field current_date which gets date.today()
This is my code but the condition unable to executed
<xpath expr="//div[hasclass('oe_kanban_content')]" position="attributes">
<t t-if="record.date_operation.raw_value < record.current_date.raw_value">
<attribute name="t-attf-style">color: red;</attribute>
</t>
<t t-else="">
<attribute name="t-attf-style">color: blue;</attribute>
</t>
</xpath>

Related

How to not allow Many2many to be able to remove its element in form view?

I have a many2many field that represents a list of student. I want to only add student to that list but not remove any students from that list (in form view). Is it possible to implement that?
I think it's possible to do it. You need to override the #write method. Each time that an update will be made on your object, you need the compare the actual length of your many2many field current_length and the new length of students made by the update new_length.
If new_length > current_length, it's means that the update is an adding, so you can consider the changes. Otherwise, it's means that the update is a removing, so you just need to ignore the changes.
Please find below, an exemple of implementation :
#api.multi
def write(self, values):
current_length = len(self.student_list)
new_length = len(values['student_list'])
if current_length > new_length:
\* Removing of students *\
values['student_list'] = self.student_list
res = super(Object, self).write(values)
return res
Note that you can go further by making another comparaison between the ids of the current and new list, in order to be sure that the students are the same.
It s not possible using the many2many_tags widget, but using the xml tree view as part of your Form view, you can add the delete-attribute on the tree-node inside the scope of your own field:
<form>
<notebook>
<sheet>
<page string="Graduated" name="gratuated_students">
<field name="students_ids" >
<tree string="Students" editable="bottom" delete="0" >
<field name="name"/>
<field name="birthday"/>
<field name="score" readonly="1"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
If this view comes from an odoo's module (no custom module): you'd rather inherit this view and add the attribute "delete=0" to the existing student_ids field:
<xpath expr="//form[1]/sheet[1]/notebook[1]/page[1]/field[#name='students_ids']/tree[1]" position="attributes">
<attribute name="delete">0</attribute>
</xpath>
Otherwise, if you really want to use the many2many_tags widget and if your are experienced with odoo's js-framework, you could develop your own option "no_delete" on the basis of the following OCA module:
https://odoo-community.org/shop/web-m2x-options-2661#attr=10772

Odoo List view: set column to be always visible

I'm working with Odoo 14 and would like to know if there is an option in XML template to suppress optional="show"/"hide" setting inherited from parent template. For example I have following code in parent template:
<field name="code" optional="show" readonly="1"/>
On a child template I would like to do something like this:
<xpath expr="//field[#name='code']" position="attributes">
<attribute name="optional">Always on</attribute>
</xpath>
to set the code field to be always on, without option to hide or show the column. Is there any option to do so?
You can inherit that field's attribute and remove it.
<xpath expr="//field[#name='code']" position="attributes">
<attribute name="optional"></attribute>
</xpath>
Solution is in fact easy, just to replace the inherited element with newly defined - without optional attribute. This rewrites all attribute settings.
<!-- In child template: -->
<xpath expr="//field[#name='code']" position="replace">
<field name="code"/>
</xpath>

Change the Position of field - Odoo

I am using Odoo 10 and I am trying to move the position of the mobile field. The below code works but the new mobile field does not have any data. Mobile number is missing. I remove that code and the mobile number comes back.
<xpath expr="//field[#name='mobile']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//field[#name='category_id']" position="after">
<field name="mobile" />
</xpath>
You cannot have same field twice in the view. You need to completely remove the field first and add it to another place after that. Your templates work if you change the first xpath to remove the field, not just hide it. This can be done like this
<xpath expr="//field[#name='mobile']" position="replace">
</xpath>
<xpath expr="//field[#name='category_id']" position="after">
<field name="mobile" />
</xpath>
Veikko`s answer is universal for all versions of Odoo but requires to rewrite full dom structure in new place
For Odoo starting version 12.0 best for move field and other is (described here):
<xpath expr="//field[#name='category_id']" position="after">
<xpath expr="//field[#name='mobile']" position="move"/>
</xpath>

Invisible two buttons using xpath in Odoo 10

In sale.order form view, there are two buttons Send by Email. One for draft state and another for sent, sale. I need to hide both buttons. I tried below code:
<xpath expr="//button[#name='action_quotation_send']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
The result is: The button in draft state become invisible, another button is still visible.
How can I hide that button too?
Use below code how it is, to hide both buttons by replacing with nothing.
<xpath expr="//button[#name='action_quotation_send']" position="replace"/>
<xpath expr="//button[#name='action_quotation_send']" position="replace"/>
I know it looks weird cause its exactly the same code twice but it worked for me.
We have to set attribute for both buttons.
Try with following code:
<xpath expr="//button[#name='action_quotation_send' and #states='sent']" position="attributes">
<attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
<attribute name="invisible">1</attribute>
</xpath
<xpath expr="//button[#name='action_quotation_send' and #states='draft']" position="attributes">
<attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
<attribute name="invisible">1</attribute>
</xpath>
I know it's late, but might help someone in future.
<xpath expr="(//button[#name='action_quotation_send'])[1]" position="attributes">
...
</xpath>
<xpath expr="(//button[#name='action_quotation_send'])[2]" position="attributes">
...
</xpath>
Refer How can you identify multiple elements with the same name in XPath?

qweb t-if in position attribures

I am developing a module in Odoo. I need to change the report of invoice to add some details.
I use xpath with position attribute and check if an affair is linked to hide the default table.
<template id="my_invoice" inherit_id="account.report_invoice_document">
<xpath expr="//div[#class='page']/table[#class='table table-condensed']" position="attributes">
<attribute t-if="o.affair_id" name="class">hidden</attribute>
</xpath>
</template>
This is not working. The default table is hidden in every invoices even if the invoice is not linked to an affair.
I do not understand because the condition works in my second template.
<template id="my_invoice2" inherit_id="account.report_invoice_document">
<xpath expr="//div[#class='page']/div[#class='row mt32 mb32']" position="after">
<t t-if="o.affair_id">
<!-- table with my additional detail -->
</t>
</xpath>
</template>
Sorry for my english. I am learning it.
try this one:
<attribute name="t-att-style">'display: none;' if o.affair_id else ''</attribute>
OR even this one also:
<attribute name="t-att-class">'hidden' if o.affair_id else ''</attribute>
it may help in your case.