odoo 8 make button invisible from compute result

42 views Asked by At

This is my .py

@api.depends('product_id')
def get_sales_divisi(self):
    for line in self:
        if line.product_id.divisi_update:
            line.sales_divisi_id = line.product_id.divisi_update.id
        elif line.product_id.divisi_ids:
            line.sales_divisi_id = line.product_id.divisi_ids.ids[0]

this is my .xml

<button name="action_approve" string="Approve Checker" type="object"  attrs="{'invisible':['|',('sales_divisi_id', '=', '2'),('sales_divisi_id', 'in', ('VET'))]}" groups="ts_addons_tbk.group_tbk_checker" />

I'm tying to make the button invisible when the sales_divisi_id is Vet but it doesn't work. Any advice please? Thank you

1

There are 1 answers

0
icra On

Assuming sales_divisi_id is a relation, in operator will query by id or name field. Furthermore, in order to use fields in queries inside your views, you need to define them first.

For example:

<field name="sales_divisi_id" invisible="1" />
<button name="action_approve" attrs="{'invisible':[('sales_divisi_id', 'in', [1,2])]}" groups="ts_addons_tbk.group_tbk_checker" />

action_approve button will show only if sales_divisi_id is related to a record having id 1 or 2.