From e9c4b7cfc57f7d6200b222881772c37b26fd74fb Mon Sep 17 00:00:00 2001 From: Laetitia Da Costa Date: Wed, 20 Nov 2024 16:55:09 +0100 Subject: [PATCH] [IMP]partner_profiles:add quick filters for admin, public and fonction profiles --- partner_profiles/__manifest__.py | 2 +- partner_profiles/models/res_partner.py | 63 ++++++++++++++++++++- partner_profiles/views/res_partner_view.xml | 28 +++++++++ 3 files changed, 90 insertions(+), 3 deletions(-) diff --git a/partner_profiles/__manifest__.py b/partner_profiles/__manifest__.py index e990147..27625e0 100644 --- a/partner_profiles/__manifest__.py +++ b/partner_profiles/__manifest__.py @@ -3,7 +3,7 @@ { "name": "partner_profiles", - "version": "16.0.1.0.1", + "version": "16.0.1.0.2", "author": "Elabore", "website": "https://elabore.coop", "maintainer": "Stéphan Sainléger", diff --git a/partner_profiles/models/res_partner.py b/partner_profiles/models/res_partner.py index 9fafb6e..7763e0b 100644 --- a/partner_profiles/models/res_partner.py +++ b/partner_profiles/models/res_partner.py @@ -287,11 +287,12 @@ class res_partner(models.Model): is_company=False, active=True, with_parent=False, + partner_profile=False ): search_values = [ ("is_company", "=", is_company), ("active", "=", active), - ("partner_profile", "=", False), + ("partner_profile", "=", partner_profile), ("type", "=", "contact") ] if id: @@ -437,4 +438,62 @@ class res_partner(models.Model): } ) count += 1 - _logger.debug("Last clean") \ No newline at end of file + _logger.debug("Last clean") + + @api.model + def _migration_main_profile_with_parent_and_not_existing_position_profile( + self, limit=None, id=False + ): + partner_profile_main = self.env.ref("partner_profiles.partner_profile_main").id + + partner_profile_position = self.env.ref("partner_profiles.partner_profile_position").id + + # Main Profil migration with parent_id + search_values = self._get_concerned_partners_search_values( + id, + with_parent=True, + partner_profile=partner_profile_main, + ) + partners = self.env["res.partner"].search(search_values, limit=limit) + _logger.debug("Main profile with parent_id - migration count: %s" % len(partners)) + count = 0 + + for partner in partners: + _logger.debug("count: [%s] : %s" % (count, partner.name)) + existing_position_partner = self.env["res.partner"].search( + self._get_position_partner_search_values(partner), + limit=1, + ) + if not existing_position_partner: + _logger.debug("CREATE Position %s" % partner.name) + self.env["res.partner"].create( + { + "name": partner.name, + "contact_id": partner.id, + "partner_profile": partner_profile_position, + "parent_id": partner.parent_id.id, + "is_position_profile": True, + } + ) + _logger.debug("UPDATE Main %s" % partner.name) + # partner.write( + # { + # "parent_id": False, + # } + #) + count += 1 + _logger.debug("### End migration ###") + + def _get_position_partner_search_values(self, partner): + return [ + ("active", "=", True), + ("type", "=", "contact"), + ("is_position_profile", "=", True), + ("is_company", "=", False), + ("contact_id", "=", partner.id), + "|", + ("name", "=", partner.name), + "&", + ("email", "!=", False), + ("email", "=", partner.email), + ] \ No newline at end of file diff --git a/partner_profiles/views/res_partner_view.xml b/partner_profiles/views/res_partner_view.xml index 056f175..8f41c79 100644 --- a/partner_profiles/views/res_partner_view.xml +++ b/partner_profiles/views/res_partner_view.xml @@ -1,6 +1,34 @@ + + res.partner.select.contact + res.partner + + + + + + + + + + Partner Profiles Form View res.partner