在我的py代码中,我获得了list_complete列表,这是字符串列表。函数action_search来自一个按钮" Search"。我想知道如何使用Python代码中的列表中的值更新视图元素(以及该元素可以是什么,如树或其他什么?)感谢。
以下是代码:
class mrp_bom(osv.Model):
_inherit = 'mrp.bom'
def action_search(self, cr, uid, ids, vals, context=None):
bom_ids = []
pd_ids = []
product_complete = []
ptemplid = int(self.browse(cr, uid, ids[0], context=context).product_tmpl_id.id)
mbl_obj = self.pool.get('mrp.bom.line')
id_s = mbl_obj.search(cr, uid, [('product_id', '=', ptemplid)])
for rec in mbl_obj.browse(cr, uid, id_s, context=context):
bom_ids.append(rec.bom_id.id)
for rec in self.browse(cr, uid, bom_ids, context=context):
pd_ids.append(rec.product_id.id)
pp_obj = self.pool.get('product.product')
for rec in pp_obj.browse(cr, uid, pd_ids, context=context):
product_complete.append('['+ str(rec.default_code) + ']'+ ' ' + str(rec.name_template))
print "\n\n Inside action_search() product_complete ", product_complete
# raise osv.except_osv(('Message!'), ('Inside action_search!' ) )
vals = {'product_id' : product_complete}
return {'value' : vals}
这是我的xml:
<record id="bom_where_use_form" model="ir.ui.view">
<field name="name">bom.where.use.form</field>
<field name="model">mrp.bom</field>
<field name="priority" eval="20"/>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="product_tmpl_id" > </field>
<button name="action_search" string="Search" type="object" class="oe_highlight"/>
<field name="bom_line_ids" widget="one2many_list">
<tree string="Components" editable="bottom">
<field name="sequence" widget="handle"/>
<field name="product_id" />
</tree>
</field>
<field name="product_id" />
</field>
</record>
答案 0 :(得分:0)
您的return
声明应该是这样的:
return {'value': {'field_name': field_value}}
在您的代码中,您尝试将列表值分配给一个简单字段,该字段是产品的ID。
我想你想要更新一些one2many字段。对于one2many和many2many值,您可能需要阅读本文档的结尾:https://doc.odoo.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html/