【发布时间】:2014-02-28 08:09:25
【问题描述】:
我正在使用 OpenERP v7.0 处理 OpenERP 自定义模块工作订单。我一直在尝试将值从父表单传递给子记录,以便准备子记录并通过 many2one 字段链接到其父记录。
我已经在父 'work_order.contract' 中重写了 create 方法:
def create(self, cr, uid, vals, context=None):
if vals.get('contracts_code','/')=='/':
vals['contracts_code'] = self.pool.get('ir.sequence').get(cr, uid, 'work_order.contracts') or '/'
order = super(contracts, self).create(cr, uid, vals, context=context)
"""Creating a contract should be able to create at least one or several
work order records so as to reflect accordingly, but it doesn't link to
the correct contract record that create it.
i.e. contract 3 creates 4 workorders"""
vals['contracts_code'] = order
for count in range(0, vals['work_orders']):
self.pool.get('work_order.work_order').create(cr, uid, {'value' : {'contracts_code': order}}, context)
return order
但是这个覆盖方法有点像:
Create (parent) --------Create (child)
| ^ |
| | |
| | v
| |______________Write (child)
v
Write (parent)
因此不会将孩子链接到其父母,因为父母的 id 仍然存在......
我尝试在父 'work_order.contract' 中使用 write 方法:
def write(self, cr, uid, ids, vals, context=None):
res = super(contracts, self).write(cr, uid, ids, vals, context=context)
"""if there's more than 1 work order in a contract, it should be able
to create the work orders accordingly linked to that contract"""
for x in range(0, vals['work_orders']):
self.pool.get('work_order.work_order').create(cr, uid, {'value' : {'contracts_code': vals['contracts_code']}}, context)
return res
这个覆盖方法看起来像:
Create (parent)
|
v
Write (parent) --------> Create (child)
^ |
|_____________Write (child)
但不知何故,需要传递的值在调用孩子创建记录的过程中不知何故消失了。
在提出这个问题时,只需意识到传递的数据是 char 而不是像 id 这样的整数,但是我不确定如何传递正确的 id,因为它还不存在(在创建过程中)。
如果我做错了,请告诉我另一种准备子记录的方法,以便了解其父记录。谢谢=)
【问题讨论】:
标签: python postgresql openerp