Skip to Content
Menu
This question has been flagged
2 Replies
2464 Rodiniai

her i compute field value:

@api.depends('item_type', 'link_with_stock_picking', 'link_with_service_requisition')
def _get_record_state(self):
self.ensure_one()
for rec in self:
po_states = []
service_state = []
po_done_state = ['cancel', 'done']
po_waiting_state = ['draft', 'assigned', 'confirmed', 'waiting']
service_done_state = ['done', 'cancel']
service_waiting_state = ['draft']
if len(rec.link_with_stock_picking) > 0 and rec.item_type == 'material':
for
picking_record in rec.link_with_stock_picking:
po_states.append(picking_record.state)
check_state_one = any(item in po_states for item in po_waiting_state)
if check_state_one == True:
rec.record_state = 'waiting_for_bill'
else
:
check_state_tow = any(item in po_states for item in po_done_state)
if check_state_tow == True:
rec.record_state = 'done'
if len
(rec.link_with_service_requisition) > 0 and rec.item_type == 'service':

for
service_record in rec.link_with_service_requisition:
service_state.append(service_record.state)
check_service_state = any(item in service_state for item in service_waiting_state)
if check_service_state == True:
rec.record_state = 'waiting_for_bill'
else
:
check_service_state_tow = any(item in service_state for item in service_done_state)
print(check_service_state_tow)
if check_service_state_tow == True:
rec.record_state = 'done'
if
rec.item_type == 'material' and not rec.link_with_stock_picking:
rec.record_state = 'draft'
else
:
if rec.item_type == 'service' and not rec.link_with_service_requisition:
rec.record_state = 'draft'

then i added this computed field in tree view,

when test it i get:

ValueError: Expected singleton: model.model(22, 23)


i tried @api.one & self.ensure_one() & limit=1 in search method but still getting the error

any idea how to work around this error

Thanks

Portretas
Atmesti
Autorius Best Answer

I solve it by replacing self with rec in search method.
because self hold many record this error raised.

Portretas
Atmesti
Best Answer


The issue is with this code, please update that code correctly.

Portretas
Atmesti
Autorius

Thank u

Related Posts Replies Rodiniai Veikla
4
bal. 17
3821
1
liep. 15
5214
2
birž. 24
1768
0
rugs. 24
1287
0
bal. 24
1226