Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
2467 Vistas

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
Descartar
Autor Mejor respuesta

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

Avatar
Descartar
Mejor respuesta


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

Avatar
Descartar
Autor

Thank u

Publicaciones relacionadas Respuestas Vistas Actividad
4
abr 17
3822
1
jul 15
5218
2
jun 24
1768
0
sept 24
1291
0
abr 24
1228