2017-03-26 5 views
0

以下の方法ではcomplete_operationアクティブIDを印刷するのに使用しましたが、Noneと表示されます。現在のIDはmrp.productionです。 mrp.operationsは、mrp.productionのone2manyフィールドです。odoo 9でone2manyのactive_idを取得する方法は?

ここ
class mrpProduction(models.Model): 
    _inherit = "mrp.production" 

    end_date = fields.Datetime('Scheduled End Date') 
    operations = fields.One2many('mrp.operations','operation_id', 'Operations') 


class mrpOperations(models.Model): 
    _name = "mrp.operations" 

    name = fields.Many2one("custom.operations", "Operation Name") 
    status = fields.Selection([('Completed','Completed'),('Pending','Pending')],'Status') 
    operation_id = fields.Integer() 

    @api.multi 
    def complete_operation(self): 
     print self.id 
     active_id=self.env.context.get('active_id') 
     print active_id,'--' 
+0

'operation_id'は' mrp.production'の 'Many2one 'でなければなりません。そして、 'complete_operation()'とは何ですか?プロダクションと操作の間にはたくさんの関係があるので、 'self.operation_id.id'(' Many2one'に変更したと仮定して)を出力/返すことができます。 – CZoellner

+1

@Mani Active Idあなたはウィザードオブジェクトを使用している場合にのみ表示されます –

答えて

0

はmrp.production

0

のmany2oneモデルがコンテキストでactive_idsという変数もありますようおoperation_idをを変更場合mrp.productionの現在のIDを保持することができますをoperation_idを。 active_idは実際にはactive_ids [0]です。

 active_ids=self.env.context.get('active_ids') 
関連する問題