Odoo Help

Welcome!

This community 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.

0

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

By
Kit Sunde
on 11/3/14, 2:54 AM 516 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?

@api.multi
def create(self, vals):
    if vals.get('allergy_ids'):
        self.add_partner_allergies(vals.get('allergy_ids')[0][2],
                                   vals.get('partner_id'))
    return super(Order, self).create(vals)


@api.multi
def write(self, vals, context=None):
    if vals.get('allergy_ids'):
        self.add_partner_allergies(
            vals.get('allergy_ids')[0][2],
            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:
    :return:
    """
    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,
                                         partner_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
1

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3918
| 5 3 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.

Ludo - Neobis
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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