[IMP] partner_profiles: sync active field values between profiles
Change in main profile is synchronized in public and position profiles. Change in public profile is sy,chronized in main and position profiles. Change in position profile is NOT synchronized in main and public profiles.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
{
|
||||
"name": "partner_profiles",
|
||||
"version": "12.0.2.3.0",
|
||||
"version": "12.0.2.3.1",
|
||||
"author": "Elabore",
|
||||
"website": "https://elabore.coop",
|
||||
"maintainer": "Stéphan Sainléger",
|
||||
|
@@ -143,6 +143,38 @@ class res_partner(models.Model):
|
||||
child.unlink()
|
||||
return super(res_partner, self).unlink()
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
super(res_partner, self).write(vals)
|
||||
if "active" in vals and not "sync_active" in vals:
|
||||
self._sync_active_profiles()
|
||||
|
||||
def _sync_active_profiles(self):
|
||||
"""Synchronize the active fields values between all the profiles of a partner.
|
||||
Change in main profile is synchronized in public and position profiles.
|
||||
Change in public profile is NOT synchronized in main and public profiles.
|
||||
Change in position profile is NOT synchronized in main and public profiles."""
|
||||
for partner in self:
|
||||
if partner.is_main_profile:
|
||||
# Sync public profile active value with main one
|
||||
public_profile = partner.public_profile_id
|
||||
if public_profile and (public_profile.active != partner.active):
|
||||
public_profile.write({"active": partner.active, "sync_active": True})
|
||||
|
||||
# Sync position profiles active value with main one
|
||||
positions = self.env["res.partner"].search(
|
||||
[
|
||||
("is_position_profile", "=", True),
|
||||
("active", "!=", partner.active),
|
||||
'|',
|
||||
("contact_id", "=", partner.id),
|
||||
("parent_id", "=", partner.id)
|
||||
]
|
||||
)
|
||||
if len(positions) > 0:
|
||||
for position in positions:
|
||||
position.write({"active": partner.active, "sync_active": True})
|
||||
|
||||
@api.model
|
||||
def search_position_partners(self, profile):
|
||||
if profile:
|
||||
|
Reference in New Issue
Block a user