This question has been flagged
2 Replies
6884 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.

Avatar
Discard
Best Answer

Hi, 

You can see following for this, it has complete explanation for company_dependent fields alongwith access restriction and python code:

https://youtu.be/GkNgc-fZO-I

Hope it helps,

Thanks

Avatar
Discard
Best Answer

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)

Avatar
Discard
Author

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

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

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