Odoo - Change specific column color in one2many tree view - odoo-8

I am using odoo 10. I have a customer view and in that customer form view i am also showing all order that are associated with that specific customer in one2many tree view (editable).
What i want to do is i want to show a button in one2many tree view but i want to change that button's color only based on condition.
Here is what i tried but its not working.
<record id="amgl.customer_form" model="ir.ui.view">
<field name="name">Customer</field>
<field name="model">amgl.customer</field>
<field name="arch" type="xml">
<form string="Create New Customer" duplicate="0">
<sheet>
<group colspan="4">
<group>
<field name="is_admin" invisible="1"/>
<field name="is_custodian" invisible="1"/>
<field name="is_vault" invisible="1"/>
<field name="is_o2m" invisible="1"/>
<field name="is_goldstar" invisible="1"/>
<field name="custodian_edit" invisible="1"/>
<field name="first_name"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="last_name"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="account_number"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="gst_account_number" string="GoldStar Account Number"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)], 'invisible':[('is_goldstar','=',False)]}"/>
</group>
<group>
<field name="date_opened"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="account_type"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="custodian_id" options='{"no_open": True}'
attrs="{'readonly':[('is_admin','=', False)]}"/>
<field name="customer_notes"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
</group>
</group>
<notebook>
<!--CURRENT INVENTORY-->
<page string="CURRENT INVENTORY">
<field name="customer_order_lines2"
attrs="{'readonly':['|',('is_custodian','=', True),('is_o2m','=', False)]}"
context="{'default_is_deposit_related': True,'group_by':'products'}"
groups="amgl.group_amark_admins,amgl.group_amark_vault,amgl.group_amark_custodian,amgl.group_amark_sub_admins"
domain="[('state','=','completed')]" default_order='state desc'
widget="one2many_list">
<h4 style="float:right;">
<field name="total_received_quantity"/>
</h4>
<tree open="false" editable="bottom"
groups="amgl.group_amark_admins,amgl.group_amark_vault,amgl.group_amark_custodian,amgl.group_amark_sub_admins">
<field name="is_deposit_related" invisible="1"/>
<field name="is_vault_edit" invisible="1"/>
<field name="is_admin" invisible="1"/>
<field style="color:red !important;" name="products" attrs="{'readonly':[('is_vault_edit','=', True)]}"/>
<field name="commodity"/>
<field name="total_received_quantity"
attrs="{'readonly':[('is_vault_edit','=', True)]}" class="oe_edit_only"
col_border="1" string="Received"/>
<field name="temp_received_weight" class="oe_edit_only" col_border="1"/>
<field name="date_received" attrs="{'readonly':[('is_vault_edit','=', True)]}"
class="oe_edit_only" col_border="1"/>
<field name="state" invisible="1"/>
<field name="notes_boolean" invisible="1"/>
<button attrs="{'invisible':[('notes_boolean','=', False)]}" type="object" name="add_notes" class="btn btn-primary btn-sm o_list_button_add">
<i class="fa-lg fa-pencil-square"></i>
</button>
<button attrs="{'invisible':[('notes_boolean','=', True)]}" type="object" name="add_notes" class="btn btn-default">
<i class="fa-lg fa-pencil-square"></i>
</button>
<!--<button colors="red: notes_boolean is True" name="add_notes" type="object"-->
<!--string="Add Notes" icon="fa-lg fa-pencil-square" class="btn btn-primary btn-sm o_list_button_addhlight"/>-->
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

What you are doing is the right solution you cannot change attributes of button using attrs
so you need to create two button with the same name and label and show or hide one of them
based on condition.
but this code will not work on tree because Odoo will not take your class attribute or style attribute
in consideration no matter what you put there if you inspect the button element in your browser you will find that
the two buttons are the same and the classes are the same and your classes are not there and there is no style attribute.
I don't know why Odoo developer decided to do so.
I needed something like this before what I did is to add css in backend_assets that select a button in tree
view with data-field attribute equal the name of the method because that attribute will not change in translation.
/* make button color red in temporary exit tree view.*/
.openerp .oe_list_content [data-field='cancel_entry'] button{
background-color: red !important;
color: white !important;
}
you will notice that only this attribute change in the buttons that are in the tree view.
so if you want to do something like this you need to to create two method
#api.multi
def add_notes_red(self): # i added _red to make sure no one else will name he's method like this
pass
#api.multi
def add_notes_green(self):
return self.add_notes_red() # because it does the same thing just call the orignal method
And in your custom css file
/* make button color red.*/
.openerp .oe_list_content [data-field='add_notes_red'] button{
background-color: red !important;
color: white !important;
}
/* make button color green.*/
.openerp .oe_list_content [data-field='add_notes_green'] button{
background-color: green !important;
color: white !important;
}
Note: Don't forget to css file in backend_assets template.

Related

TypeError: dict.record.id is undefined when I access to my custom kanban view in Odoo 11

I have a custom module that had a kanban view. His model inherits from res.users (and res.users inherits from res.partner).
I have a problem when I try to access to kanban view of my module. I know where is the error, but i don´t have idea for how to solve.
The error is:
Error: QWeb2 - template['kanban-box']: Runtime Error: TypeError: dict.record.id is undefined
This is my kanban view (maestro):
<record model="ir.ui.view" id="maestro_kanban_view">
<field name="name">maestro.kanban.view</field>
<field name="model">aula10.maestro</field>
<field name="groups_id" eval="[(4, ref('grupo_maestros'))]"/>
<field name="arch" type="xml">
<kanban>
<field name='name'/>
<field name='image'/>
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_global_click">
<div class="o kanban_image">
<img t-att-src="kanban_image('maestro','image_medium', record.id.value)"/>
<div class="oe_kanban_details">
<!-- Title and Data content -->
<h4>
<a type="open">
<field name="name"/>
</a>
</h4>
</div>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
I know the problem is in the image, in record.id.value, because when I erase the img tag, the error disappear.
How can I fix this?
In kanban view you must mention every fields you use in the field list like in your code you have mentioned two fields nameand image just add id to them and Odoo should recognize it.
<field name='id'/>
<field name='name'/>
<field name='image'/>

Make a delete button invisible using attrs. I am using Odoo 10

I need to make a delete button invisible using attrs.
my code here.
in this code i want to put invisible delete button.
<record id="calender_event_form_id1" model="ir.ui.view">
<field name="name">calender_event</field>
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_form_popup"/>
<field name="arch" type="xml" delete="false">
<xpath expr="//field[#name='partner_ids']" position="after">
<field name="c_is_meeting_done" string="Is Meeting Done?" readonly="1"/>
<field name="description"/>
</xpath>
<xpath expr="//field[#name='alarm_ids']" position="after">
<div name="buttons">
<button name="%(ouc_meeting_wizard_action)d" string="Close Meeting" attrs="{'invisible':[('c_is_meeting_done', '=', True)]}" type="action" class="oe_highlight" />
</div>
</xpath>
</field>
</record>
You can give "delete=1" to your particular view from xml. Like this:
<form string="Custom" delete="1"/>

Adding a Button in Tree View Odoo 8

I've Created a Wizard in Tree View Mode and Just Want to add some button with it, is there a way to this in odoo 8?
Thanks
Yes, you can add button in the tree view like you are adding in the form view.
<tree string="My Tree">
<button name="%{action_wiz_open}d" string="Scrap Products" type="action" icon="terp-gtk-jump-to-ltr" help="calls window action" />
<button name="call_function" string="Process" type="object" help="calls python function" />
</tree>
Hope this helps!
To add a button in tree view try below code:
<tree>
<button name="your_action" icon="rupee-symbol"
String="Payment" type="action"
attrs="{'invisible':[('status','!=','Confirmed')]}" />
</tree>
Hope it will help you..
Create a folder wizard
which will have
__init__.py
file_name.py
file_name_view.xml
In Python file_name.py
def fields_view_get(self, cr, uid, view_id=None, view_type='form',
context=None, toolbar=False, submenu=False):
if context is None:
context={}
res = super(class_name_wizard, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
return res
Add your function next to it
In file_name_view.xml
<record model="ir.ui.view" id="new_id">
<field name="name">New Wizard</field>
<field name="model">my.wizard</field>
<field name="arch" type="xml">
<form string="New Form">
<header>
<button name="do_generate" string="My Function" type="object"/>
or
<button string="Cancel" class ="oe_link" special="cancel"/>
</header>
</form>
</field>
</record>
<record id="action_my_function_wizard" model="ir.actions.act_window">
<field name="name">My Function</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">my.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<act_window name="My Function"
res_model="my.wizard"
src_model="product.master"
view_mode="form"
target="new"
multi="True"
key2="client_action_multi"
id="action_view_my_new_id"/>
Note:In src_model write the table name of the tree view
Hope this will help you

How do I get an editable multilines layout in OpenERP?

I want to create Delivery orders based on a selection of order lines to invoices (as shown below) with the possibility to adjust quantity used in the delivery order.
Expected UI
Looking around, I found a UI similar to want I want in Delivery orders > More > Return Shipments (cf. _stock/wizard/stock_return_picking_view.xml_).
What I got
But I don't get the same result with my XML
view.xml
<record id="view_create_delivery_button" model="ir.ui.view">
<field name="name">Create Delivery</field>
<field name="model">sale.order.line</field>
<field name="arch" type="xml">
<form string="Create Delivery" version="7.0">
<label string="Select the quantities to create."/>
<group>
<field name="order_id"/>
<field name="name"/>
<field name="product_uom_qty"/>
<field name="state" invisible="1" />
</group>
<footer>
<button name="create_returns" string="Create delivery" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
Question
How do I get this editable multilines layout?
What you see in the Return Shipments wizard is a one2many field that related to stock.return.picking.line on it tree view with editable=top attribute.
I am assuming this is what you wanted:
<record id="view_create_delivery_button" model="ir.ui.view">
<field name="name">Create Delivery</field>
<field name="model">sale.order</field>
<field name="arch" type="xml">
<form string="Create Delivery" version="7.0">
<label string="Select the quantities to create."/>
<field name="order_line" >
<tree editable="top">
<field name="order_id"/>
<field name="name"/>
<field name="product_uom_qty"/>
<field name="state" invisible="1" />
</tree>
</field>
<footer>
<button name="create_returns" string="Create delivery" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
Note: This is just a sample of how to use the field many2one's tree view, you might need adjust to your on needs.

Odoo v9 edit record with view_type=tree

I have to show the records of a custom module in a tree view (not list)
<field name="view_type">tree</field>
Instead of
<field name="view_type">form</field>
However, I would also like to be able to go to the records' corresponding forms when I click on them. Based on what I read, it's not possible, at least not by default. Is there any workaround to 'fix' it?
Here is my code:
<!-- Estrutura de Redes -->
<record id="edit_estrutura" model="ir.ui.view">
<field name="name">gestao.rede.estrutura.form</field>
<field name="model">gestao.rede.estrutura</field>
<field name="arch" type="xml">
<form string="Estrutura da Rede">
<header>
<!--<button name="" string="Desabilitar" type="object" states="habilitado"/>-->
<!--<button name="" string="Habilitar" type="object" states="desabilitado"/>-->
</header>
<sheet string="Estrutura da Rede">
<div class="oe_nome">
<label for="razao_social" class="oe_edit_only" string="Nome"/>
<h1>
<field name="name" string="Nome:"/>
</h1>
<label string="Pasta Acima:"/>
<field name="parent_id" options="{'no_create': True}"/>
<label string="Variável:"/>
<field name="variavel"/>
<label string="Pastas Abaixo:" class="oe_read_only"/>
<field name="pastas_filho" options="{'no_create': True}" class="oe_read_only"/>
</div>
</sheet>
</form>
</field>
</record>
<record id="view_estrutura_tree" model="ir.ui.view">
<field name="name">gestao.rede.estrutura.tree</field>
<field name="model">gestao.rede.estrutura</field>
<field name="field_parent">pastas_filho</field>
<field name="arch" type="xml">
<tree string="Estrutura da Rede" delete="true" editable="bottom/top" toolbar="1">
<field name="name"/>
<field name="pastas_filho"/>
<field name="parent_id"/>
<field name="variavel"/>
</tree>
</field>
</record>
<record id="open_view_gestao_estrutura_all" model="ir.actions.act_window">
<field name="name">Estrutura da Rede</field>
<field name="res_model">gestao.rede.estrutura</field>
<field name="view_type">tree</field>
<field name="domain">[]</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_estrutura_tree"/>
</record>
<menuitem action="open_view_gestao_estrutura_all" id="menu_action_estrutura" parent="menu_gestao_redes" sequence="20"/>
Thanks!
Editable Tree View
by default, selecting a list view's row opens the corresponding form view. The editable attributes makes the list view itself editable in-place.
Valid values are top and bottom, making new records appear respectively at the top or bottom of the list.
The architecture for the inline form view is derived from the list view. Most attributes valid on a form view's fields and buttons are thus accepted by list views although they may not have any meaning if the list view is non-editable
Example:
<tree editable="bottom/top">
<field name="xyz"/>
</tree>
Try this
<tree editable="bottom">
Add your fields
</tree>

Resources