diff --git a/partner_profiles/__manifest__.py b/partner_profiles/__manifest__.py index 27625e0..e9beb75 100644 --- a/partner_profiles/__manifest__.py +++ b/partner_profiles/__manifest__.py @@ -3,7 +3,7 @@ { "name": "partner_profiles", - "version": "16.0.1.0.2", + "version": "16.0.1.1.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 9826493..281c922 100644 --- a/partner_profiles/models/res_partner.py +++ b/partner_profiles/models/res_partner.py @@ -4,6 +4,7 @@ import logging from odoo import _, api, fields, models from odoo.exceptions import UserError +from odoo.osv import expression _logger = logging.getLogger(__name__) @@ -437,3 +438,25 @@ class res_partner(models.Model): } ) count += 1 + + @api.model + def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): + #TODO: should be moved in partner_contact_in_several_companies module + """Display only standalone contact in domain or having attached contact in domain""" + ctx = self.env.context + if ( + ctx.get("search_show_all_positions", {}).get("is_set") + and not ctx["search_show_all_positions"]["set_value"] + ): + domain = expression.normalize_domain(domain) + attached_contact_domain = expression.AND( + (domain, [("contact_type", "=", "attached")]) + ) + attached_contacts = self.search(attached_contact_domain) + domain = expression.OR( + ( + expression.AND(([("contact_type", "=", "standalone")], domain)), + [("other_contact_ids", "in", attached_contacts.ids)], + ) + ) + return super().read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy) \ No newline at end of file