This question has been flagged
2 Replies
23268 Views

I need to use the values generated by a computed field in a domain, to hide specific lines in a tree view, I don't know if I'm using the domain in the wrong way. Exist other way to do what I need? Here's my code:

Python:

What I have done so far is to create a second field that stores the value of the computed field and apply it to the domain. Did not work

@api.one
def method_compute_invoice(self):

res = ''
if self.sale_id:
res = self.sale_id.state
_state = {'draft' : 'Draft Quotation', 'sent' : 'Quotation Sent', 'cancel' : 'Cancelled', 'waiting_date' : 'Waiting Schedule', 'progress' : 'Sales Order',
'manual' : 'Sale to Invoice', 'shipping_except' : 'Shipping Exception', 'done' : 'Done'}
res = _state.get( res, res )

if self.sale_id.invoiced:
res += '/invoiced'

if self.sale_id.shipped:
res += '/shipped'

self.compute_invoice = res
sql = "update visio_prepare_shipment_list set store_invoice = '%s' where id = %s" % (res, self.id)
self.env.cr.execute(sql)
# fields
compute_invoice = fields.Char('Current Odoo order Status', compute='method_compute_invoice')
store_invoice = fields.Char('Current Odoo order Status')

XML:

record id="action_prepare_shipment_tree" model="ir.actions.act_window">            <field name="name">Prepare For Shipment</field>            <field name="type">ir.actions.act_window</field>            <field name="res_model">visio.prepare.shipment.list</field>            <field name="view_type">form</field>            <field name="view_mode">tree,form</field>             <field name="search_view_id" ref="prepare_shipment_filter"/>            <field name="context">{'search_default_PackingList': 1}</field>            <field name="domain">[('store_invoice','!=','Done/invoiced/shipped')]</field>        </record>
Avatar
Discard
Best Answer

Hi,

For using computed field in the domain you have to give  store=True for the field . If you didn't give store=True, you cannot use the field for giving in the domain.

For more info you can check this link , https://www.odoo.com/forum/help-1/question/how-can-i-use-a-field-function-in-the-domain-filter-137

Eg:-

amount_total = fields.Monetary(compute=_amount_all, string='Total', store=True)

Thanks


Avatar
Discard
Best Answer
Hi,
You should add   store=True 

compute_invoice = fields.Char('Current Odoo order Status',  compute='method_compute_invoice',store=True)

and you should add your computed field to the tree view (even invisibble) like:

<field name="compute_invoice" invisible="1" />

and than you can use it in your domain inside the tree

Avatar
Discard