0

I'd like to modify res_partner in an onchange. I'm currently doing this:

@api.onchange('my_field')
def onchange_model_type(self):
    var = 0
    for res_id in res_partner:
        if self.name == res_id: #name is a many2one in this model which   
                                #leads to res_partern
                                #I check here if res_id is the good partner
            res_id.house = 2 #house is a many2one in res_partner to
                                #a 3rd model.

I get : NameError: global name 'res_partner' is not defined

How do I import res_partner so I don't have this error anymore and I can modify it?

(I already tried self.name.house = 2 but it don't works, that's why I go straight to res_partner)

T.Nel
  • 1,540
  • 2
  • 18
  • 34
  • replace `res_partner` with `self.res_partner` – mokiSRB May 19 '16 at 09:14
  • I get an error: AttributeError: 'my_model' object has no attribute 'res_partner' – T.Nel May 19 '16 at 09:26
  • You have to inherit `res_partner` – mokiSRB May 19 '16 at 09:29
  • Ok I will try that. If you find any solution that would allow me to do it without inherit, tell me. I've noticed in my database that when I inherit, it had every columns of the class in the original res_partner. I'd like that not to happen. More of that I already inherited res_partner in that module and did a many2one to it. – T.Nel May 19 '16 at 09:47
  • If you have `many2many` on `res_partner` you can use that field in `for` loop. – mokiSRB May 20 '16 at 09:52
  • I kind of solved my problem. I used @api.depends in the res partner with a one2many. If someone one day need more info, I detailled it here [http://stackoverflow.com/a/37344100/6345404] – T.Nel May 20 '16 at 10:22

0 Answers0