Skip to Content
Menu
This question has been flagged
2 Replies
1751 Views

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

Avatar
Discard
Author Best Answer

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

Avatar
Discard
Best Answer


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

Avatar
Discard
Author

Thank u

Related Posts Replies Views Activity
4
Apr 17
3098
1
Jul 15
3990
2
Jun 24
225
0
Sep 24
380
0
Apr 24
361