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.

1

How to copy value of a "company_dependent" field (Property field in Odoo 7 and before) from one company to another?

By
Tanveer Singh
on 4/4/16, 6:20 AM 441 views

I have a setup with multiple companies. (lets call them A, B, C)

There are some property fields (called company_dependent field from 8.0 onwards).

How to copy the value of a property field value from one company to another company.

Suppose for many2many field "worker" if a user (with company currently set to 'A') changes the value and selects a particular worker, I need a way to set similar value for the field "worker" for companies B & C also.

Is there a way to just copy of the value of the field and somehow change the 'company' it is associated with or do I have to edit the 'ir.property' Object and create the property records manually to achieve the result I need above.

0

Try this:

// property_name -> name of the property to copy
// model -> model that contains the property
// ids -> ids of the objects from "model" to copy the property values
// source_company_id -> source company
// target_company_id -> target company


code:

@api.model
def copy_multi_property(self, property_name, model, ids, source_company_id, target_company_id):
  property = self.env['ir.property']
  source_property = property.with_context(force_company=source_company_id)
  target_property = property.with_context(force_company=target_company_id)
  values = source_property.get_multi(property_name, model, ids)
  target_property.set_multi(property_name, model, values)

Ideally synchronized but just copy once will work for us for the time being...

Tanveer Singh
on 4/6/16, 1:38 AM

If you extend the ir.property object then use "self" instead "property"

Yurdik Cervantes Mendoza
on 4/6/16, 10:09 AM

For the syncronization think about using "action rules". Look at this: http://bit.ly/1qrvy3L

Yurdik Cervantes Mendoza
on 4/6/16, 10:11 AM

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

1 follower(s)

Stats

Asked: 4/4/16, 6:20 AM
Seen: 441 times
Last updated: 4/6/16, 4:58 PM