跳至内容
菜单
此问题已终结
2 回复
2491 查看

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

形象
丢弃
编写者 最佳答案

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

形象
丢弃
最佳答案


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

形象
丢弃
编写者

Thank u

相关帖文 回复 查看 活动
4
4月 17
3835
1
7月 15
5232
2
6月 24
1775
0
9月 24
1311
0
4月 24
1247