This question has been flagged
1 Reply
9545 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 http://10.10.10.40:8078/web/static/lib/py.js/lib/py.js:370 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
                else:
                    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}"/>
                    </tree>
                </xpath>

            </field>
        </record>

Thanks and greetings

Avatar
Discard

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

Author

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

Best Answer

Try to use (for inherited view):

<tree position="attributes">

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

</tree>

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

Avatar
Discard
Author

Thanks, I'll try.

Author

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.