I want to display some data from different database tables to the user. Because the data is in different database tables and I want to display them together. To do that I was thinking of adding a new class which only inherits from ModelView. The base class:
class WorkInstruction(ModelView, ModelSQL, DeactivableMixin):
"Work instructions for projects"
__name__ = 'project.work.workinstruction'
tools = fields.One2Many('project.work.used.tools', 'workinstruction', 'Tools')
The tools field is connected to the ModelView only class. The data can be accessed from a table which resides between them.
class MoveResources(ModelSQL, ModelView):
'Resources linked to a move'
__name__ = 'move.resources'
resource = fields.Reference('Resource', selection='get_resource')
move = fields.Many2One('stock.move', 'Move', ondelete='CASCADE',
select=True,
states={
'readonly': Eval('move_state') != 'draft'
},
depends=['move_state'])
class WorkTools(ModelView):
'List of tools used on a work instruction'
__name__ = 'project.work.used.tools'
workinstruction = fields.Many2One('project.work.workinstruction', 'WorkInstruction')
product = fields.Many2One('product.product', 'Product')
@classmethod
def search(cls, clause, order):
pool = Pool()
Resource = pool.get('move.resources')
res = []
for search in clause:
if search[0] == 'workinstruction':
reffield = ['project.work.workinstruction,%s' % search[2][0] ]
wi = Resource.search([('resource', 'in', reffield)])
for i in wi:
res.append({
'workinstruction': search[2][0],
'product': i.move.product,
})
return res
Because the ModelView doesn’t have a search
function, I added one myself. I’m just collecting the data from the database and put that into an array of dictionaries. When I add the tools
field to the form XML, I always get an AttributeError
Traceback (most recent call last):
File "/lib/python3.6/site-packages/trytond/protocols/dispatcher.py", line 176, in _dispatch
result = rpc.result(meth(*c_args, **c_kwargs))
File "/lib/python3.6/site-packages/trytond/model/modelsql.py", line 809, in read
getter_result = field.get(ids, cls, fname, values=result)
File "/lib/python3.6/site-packages/trytond/model/fields/one2many.py", line 141, in get
origin_id = getattr(target, self.field).id
AttributeError: 'dict' object has no attribute 'workinstruction'
What am I missing here?