Odoo Help


Using colors attribute

Mayela Miranda
on 9/22/14, 12:12 PM 2,610 views

Hi everybody, I'm really newbie in Odoo(OenERP) and I don't how to use correctly the colors attribute inside a tree tag.

I created a field called vencido on account.invoice model and I tried to change the color in the tree view  of the invoices but I got the error Error: NameError: name 'vencido' is not defined so I tried the same but  with the base fields sent and reconciled and I got the same error so my question is, How using the colors attribute? Could I use with a boolean field?

Here my complete code.

from openerp.osv import fields, osv
import time
from datetime import datetime, date, timedelta

class account_invoice_vencido_msm(osv.Model):
    _inherit = 'account.invoice'

    def _calcula_vencimiento(self, cr, uid, ids, field, arg , context=None):
        res = {}
        for j in self.browse(cr, uid, ids, context=context):
            if j != None:
                hoy = date.today
                delta = hoy - j.date_invoice
                treinta_dias = timedelta(30).days
                if j.date_due >= date.today():
                    res[j.id] = True
                    res[j.id] = False
        return res

    _columns = {
        'vencido' : fields.function(_calcula_vencimiento, method=True, type='boolean', string='Vencido'),


<record id="factura_msm" model="ir.ui.view">
            <field name="name">factura.msm</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="account.invoice_tree"/>
            <field name="priority" eval="500"/>
            <field name="arch" type="xml">

                <xpath expr="//tree[@string='Invoice']" position="replace">
                    <tree colors="red:vencido == True" string="Factura">
                        <field name="partner_id" modifiers="{'readonly': [['state', 'not in', ['draft']]], 'required': true}" string="Proveedor"/>
                        <field name="commercial_partner_id" invisible="1" modifiers="{'readonly': true, 'tree_invisible': true}"/>
                        <field name="date_invoice" modifiers="{'readonly': [['state', 'not in', ['draft']]]}"/>
                        <field name="section_id" invisible="1" modifiers="{'tree_invisible': true}"/>
                        <field name="number" modifiers="{'readonly': true}"/>
                        <field name="reference" invisible="0" modifiers="{'tree_invisible': true}"/>
                        <field name="name" invisible="1" modifiers="{'readonly': [['state', 'not in', ['draft']]], 'tree_invisible': true}"/>
                        <field name="journal_id" invisible="1" modifiers="{'readonly': [['state', 'not in', ['draft']]], 'required': true, 'tree_invisible': true}"/>
                        <field name="period_id" invisible="1" modifiers="{'readonly': [['state', 'not in', ['draft']]], 'tree_invisible': true}"/>
                        <field name="company_id" widget="selection" invisible="1" modifiers="{'invisible': true, 'readonly': [['state', 'not in', ['draft']]], 'required': true, 'tree_invisible': true}"/>
                        <field name="user_id" modifiers="{'readonly': [['state', 'not in', ['draft']]]}"/>
                        <field name="date_due" modifiers="{'readonly': [['state', 'not in', ['draft']]]}"/>
                        <field name="origin" modifiers="{'readonly': [['state', 'not in', ['draft']]]}"/>
                        <field name="currency_id" invisible="1" modifiers="{'invisible': true, 'readonly': [['state', 'not in', ['draft']]], 'required': true, 'tree_invisible': true}"/>
                        <field name="residual" sum="Importe residual" modifiers="{'readonly': true}"/>
                        <field name="amount_untaxed" sum="Base imponible" modifiers="{'readonly': true}"/>
                        <field name="amount_total" sum="Importe total" modifiers="{'readonly': true}"/>
                        <field name="state" modifiers="{'readonly': true}"/>


Thanks and greetings

When are you getting this error ?? Is it during the installation of your module ?

Med Said BARA
on 9/22/14, 12:37 PM

No, it's when I go to the tree view of invoices for see the all existing invoices. Thanks for reply.

Mayela Miranda
on 9/22/14, 1:06 PM

Med Said BARA

--Med Said BARA--

| 5 5 7
--Med Said BARA--
Med Said BARA
On 9/22/14, 1:11 PM

Try to use (for inherited view):

<tree position="attributes">

     <attribute name="colors">red:vencido==True</attribute>


Maybe you should use the parameter " store=" in your function, by default it's set to False, and also change field to field_name.

Thanks, I'll try.

Mayela Miranda
on 9/22/14, 2:10 PM

That didn't work for me, I got the same error. I thought that my .py didn't consider but no, because I changed the parameter string and it was updated. Thanks so much I'll continue trying.

Mayela Miranda
on 9/22/14, 2:52 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 9/22/14, 12:12 PM
Seen: 2610 times
Last updated: 3/16/15, 8:10 AM