如何覆盖创建函数Odoo

时间:2018-03-07 23:12:35

标签: python xml odoo

我正在创建Odoo模型,我想在create

上触发一个函数

*更多信息:

*班级旅游:

class obj_tour(osv.osv):
    _name = "obj.tour"
    _description = "Objet tour"
    _columns = {
       'id_trans' : fields.many2one('obj.gtransport',"Transport",selection=_get_selection_transport,required = True),# foreign key
    }
    ...

*班级运输

class obj_gtransport(osv.osv):
    _name = "obj.gtransport"
    _description = "Objet gtransport"
    _rec_name = "matricule"
    _columns = {
        'est_dispo': fields.boolean( "Disponible"),
    }
    ...

我想触发当我在巡视中使用传输时传输将更改(est_dispo布尔值为false)

*照片: enter image description here enter image description here

我试图覆盖create函数,但它不会改变boolean值

图:

from openerp import models, fields, api

class obj_tour(models.Model):
    _inherit = 'obj.tour'
    @api.model
    def create(self, values):
        record = super(obj_tour, self).create(values)
        if 'id_trans' in values:
            trans_id = values['id_trans']
            trans_model = self.env['obj.gtransport']
            domain = [('matricule', '=', trans_id)]
            trans_ids = [idn.id for idn in trans_model.search(domain)]
            ts = trans_model.browse(trans_ids)
            for obj in ts:
               #obj.est_dispo = False
                obj.write({'est_dispo' : False})
        return record

任何想法?

1 个答案:

答案 0 :(得分:1)

覆盖tour对象的create方法&在传输对象中将Boolean赋值为false。