Odoo Help


I want to copy fields to the partner on saving an order, is there a nice way of doing that?

Kit Sunde
on 11/3/14, 2:54 AM 1,019 views

Currently I'm overring create and write to copy the fields onto the partner, is there a cleaner way of updating the partner on save?

def create(self, vals):
    if vals.get('allergy_ids'):
    return super(Order, self).create(vals)

def write(self, vals, context=None):
    if vals.get('allergy_ids'):
            vals.get('partner_id', self.partner_id.id))

    return super(Order, self).write(vals)

def add_partner_allergies(self, allergy_ids, partner_id):
    Populates the partner with allergies from the order for the future.
    :param allergy_ids:
    :param partner_id:
    domain = [('id', '=', partner_id)]
    partners = self.env['res.partner'].search(domain)
    allergies = copy.deepcopy(allergy_ids)
    partner_allergies = partners[0].allergy_ids.ids
    allergies = list(set(itertools.chain(allergies,

    partners.write({'allergy_ids': [(6, False, allergies)]})

Why don't you add partner field to the order model?

Ben Bernard
on 11/3/14, 3:38 AM

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
| 5 5 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 11/3/14, 5:51 AM

create a many2many field 'partner_allergies' at Partner.

In Sale order, create a related field 'partner_allergies' that link to that particular partner.

In general, RELATED fields have this feature
      value always changes if the related field is changed at parent object and vice-versa. 


Good suggestion. Very clean.

21south, Ludo - 21South
on 11/3/14, 6:03 AM

The data isn't actually relational, it's two different sets. 1 is allergies with regards to the order, which is specific only to that. 1 is the defaults on the partner. It would be bad if editing the partners allergies would result in allergies being removed from orders that haven't shipped yet.

Kit Sunde
on 11/3/14, 12:02 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 11/3/14, 2:54 AM
Seen: 1019 times
Last updated: 3/16/15, 8:10 AM