Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
2475 Widoki

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź


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

Awatar
Odrzuć
Autor

Thank u

Powiązane posty Odpowiedzi Widoki Czynność
4
kwi 17
3831
1
lip 15
5224
2
cze 24
1773
0
wrz 24
1303
0
kwi 24
1237