This question has been flagged
5 Replies
3302 Views

I've created my own field company_origin. It is only visible if the partner (res.partner modell) is a company.

The field company_origin is a Many2one field, related to a modell origin which i added to res_partner.

My Problem is that i can't write values into the children of the company. For some fields it works (e.g. street) but for some it doesn't. (e.g. website). I also can not write the fields that i added to res.partner with my own model.

Here is some code that shows my problem, street changes but website doesnt (both are fields.Char() fields).


    @api.onchange('company_origin')
    def _set_children_origin(self):
        if self.child_ids != False:
            #--------------------------#
            for child in self.child_ids:
                child.street = "teststreet"
                child.website = "testsite"


Thanks, for any advice.

Avatar
Discard

Both fields are in the view xml?

Author

Yes i can see both fields and they are defined in res.partner (view). I use _inherit=res.partner in my modell to add new elements. But those two fields both are untouched. I really would like to know why i can not write into child.website. Thanks for your reply.

Best Answer

see documentation (not tested) :


http://odoo-new-api-guide-line.readthedocs.org/en/latest/environment.html

Many2many One2many Behavior

One2many and Many2many fields have some special behavior to be taken in account. At that time (this may change at release) using create on a multiple relation fields will not introspect to look for the relation.


self.line_ids.create({'name': 'Tho'}) # this will fail as order is not set

self.line_ids.create({'name': 'Tho', 'order_id': self.id}) # this will work

self.line_ids.write({'name': 'Tho'}) # this will write all related lines

Avatar
Discard
Best Answer

I previously poorly understood your construction. Now my answer:

  • @api.onchange scope is limited to the same screen / model

you define relation fields in your model, if it is necessary.


PS> line

if self.child_ids != False: 

is redundant



Avatar
Discard
Author Best Answer

It is possibke to write, if I use self.env['res.partner'].browse(child.id).write({'website': "test"}) .

If someone knows why it doesnt work with child.website = ..., pls help out. Would be interesting to know how those operations are different and how they really work.

Avatar
Discard