12.0 improve profiles management #4

Merged
stephansainleger merged 28 commits from 12.0-improve_profiles_management into 12.0 2023-06-27 15:31:24 +00:00
2 changed files with 33 additions and 1 deletions
Showing only changes of commit b7496f99b5 - Show all commits

View File

@@ -3,7 +3,7 @@
{ {
"name": "partner_profiles", "name": "partner_profiles",
"version": "12.0.2.3.0", "version": "12.0.2.3.1",
"author": "Elabore", "author": "Elabore",
"website": "https://elabore.coop", "website": "https://elabore.coop",
"maintainer": "Stéphan Sainléger", "maintainer": "Stéphan Sainléger",

View File

@@ -143,6 +143,38 @@ class res_partner(models.Model):
child.unlink() child.unlink()
return super(res_partner, self).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 @api.model
def search_position_partners(self, profile): def search_position_partners(self, profile):
if profile: if profile: