简体   繁体   中英

Workaround for Many2One or One2Many relationships from non-transient Model to TransientModel in Odoo

I want to create a relationship between non transient model and transient model in ODOO-10. we have create a transient model which does some complex computations, now we want to display this data on a non-transient models form but could not achieve this because of transient and non-transient model relationship restrictions

The only relationship allowed between a normal Model and transien One is:

          T   ---- M2o   ----- > M
          M ------ M2M   ------> T

So if you want a behavior like One2many use a Computed Many2many and fill it witch a simple search call.

In your non transient model define a button for opening wizard.

In Non Transient Model

def open_wiz(self):
    wiz=self.env['your_wizard_name'].create(
        {
        'xn_id':self.id, #your_non transient_model's id #not compulosory
        'field1':feild1_data,
        'field2':field2_data
        }
    return {

                'name':'Display',
                'view_type':'form',
                'view_mode':'form',
                'res_model':'your_wizard_model_name',
                'type':'ir.actions.act_window',
                'res_id':wiz.id,
                'target':'new',

            }

In Tansient Model

If you want to change the data from the wizard and to reflect in your Non Transient Model,call Super of Write function and pass data. Eg:

@api.multi
def write(self,vals):
    res=super(wiz_class_name,self).write(vals)
    self.xn_id.write({'field1':self.data_from_wiz})
    return res

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM