gpt4 book ai didi

python - odoo Fill one2many 从一个模型到另一个模型

转载 作者:太空宇宙 更新时间:2023-11-03 10:52:29 28 4
gpt4 key购买 nike

为了将数据从 mro.request 传输到 mro.order 我创建了一个名为 action_confirm 的函数并且还为我的工作流程,新对象的创建也完美地完成了从 chardate 的数据传输...但是为了填充 one2many字段它不起作用,我没有收到任何错误。

我的按钮类型是workflow我知道我遗漏了一些东西,只是想不通。在下面,您可以找到我的代码……最好的问候

我的模型:

1/

 class mro_request(osv.osv):

_name = 'mro.request'

_columns = {
'intervention': fields.one2many('fleet.service.type.line','intervention_id','Order réparations', help='Cost type purchased with this cost'),
'priority' : fields.selection([('0', 'Not urgent'), ('1', 'Normale'), ('2', 'Urgent'), ('3', 'Tres Urgent'),('4', 'Critique')], 'Priorité',
select=True, readonly=True, states=dict.fromkeys(['draft', 'confirmed'], [('readonly', False)])),
}

@api.multi
def action_confirm(self):
or_object = self.env['mro.order']
affectation_line = self.env['fleet.service.type.line']


## creating maintenance order object is working
obj = {'state': 'draft', 'date_planned' : self.execution_date,'intervention': self.intervention,
'asset_id' : self.asset_id.id, 'description': self.description}
purchase_id = or_object.create(obj)


list_intervention=[]
for line in self.intervention :
art = {}

art['desc'] = line.description
art['intervention_type'] = line.intervention_type.name

art_id = affectation_line.create(art)
list_intervention.append(art_id)

self.write({'state': 'run'})

return True

2/

 class mro_order(osv.osv):

_name = 'mro.order'

_columns = {
'intervention': fields.one2many('fleet.service.type.line','intervention_id','Order réparations', help='Cost type purchased with this cost'),
'priority' : fields.selection([('0', 'Not urgent'), ('1', 'Normale'), ('2', 'Urgent'), ('3', 'Tres Urgent'),('4', 'Critique')], 'Priorité',
select=True, readonly=True),
}

3/

class fleet_service_type_line(osv.Model):
_name = 'fleet.service.type.line'
_description = 'Type of services available on a vehicle'
_columns = {

'intervention_id' : fields.many2one('mro.request'),
'intervention_type' : fields.many2one('fleet.service.type','Type Intervention'),
'intervention_mro' : fields.many2one('mro.order','Type Intervention'),
'user_id' : fields.many2one('res.users', 'Chef Atelier', help="Workshop Chief"),
'desc' : fields.char('desc'),

}

最佳答案

试试这个:

 @api.multi
def action_confirm(self):
or_object = self.env['mro.order']

## creating maintenance order object is working
obj = {
'state': 'draft',
'date_planned' : self.execution_date,
'intervention': self.intervention,
'asset_id' : self.asset_id.id,
'description': self.description
}

# before you create your model add the list
# of records to be created in intervention
list_intervention=[]
for line in self.intervention :
art = {}
art['desc'] = line.description
art['intervention_type'] = line.intervention_type.name
# x2many field accept list of cammands (command, value1, value2)
# for create pass 0 in cammand and a dictionary in value2
list_intervention.append((0, 0, art))

obj.update({ # add the list of command to obj
'intervention': list_intervention,
})
# now the create method will create the record in intervention too
or_object = or_object.create(obj)
self.write({'state': 'run'})
return True

关于python - odoo Fill one2many 从一个模型到另一个模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47485517/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com