爲了將數據從mro.request
轉換爲mro.order
我創建了一個名爲action_confirm
的函數,並且爲我的工作流程創建了一個轉換,新對象的創建也可以完美地傳遞數據char
,date
...但爲了填補one2many
字段,它不起作用,我沒有得到任何錯誤。odoo將one2many從模型填充到另一個模型
我的按鈕類型是workflow
我知道我失去了一些東西,只是不能圖out.below,你找到我的代碼...最好的問候
我的模型:
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'),
}
你嘗試什麼@Zety這裏提出https://stackoverflow.com/questions/39524632/how-to-automatically-fill-a-one2many-字段值到另一個2many-field-in-o – user3676872
它沒有工作。 – imad