From 9194312cbf4e6afe2cdffb9f546a04e5b86cebbd Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Thu, 20 Aug 2015 14:27:03 +0200 Subject: [PATCH] [FIX] respect restrictions on possible relation types and other partner fixes #160 --- .../model/res_partner_relation_all.py | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/partner_relations/model/res_partner_relation_all.py b/partner_relations/model/res_partner_relation_all.py index de1f96056..991120bec 100644 --- a/partner_relations/model/res_partner_relation_all.py +++ b/partner_relations/model/res_partner_relation_all.py @@ -162,16 +162,42 @@ class ResPartnerRelationAll(models.AbstractModel): @api.onchange('type_selection_id') def onchange_type_selection_id(self): - """Add domain on other_partner_id according to category_other""" - if not self.type_selection_id.partner_category_other: - return {'domain': []} - is_company = self.type_selection_id.partner_category_other == 'c' + """Add domain on other_partner_id according to category_other and + contact_type_other""" + domain = [] + if self.type_selection_id.contact_type_other: + domain.append( + ('is_company', '=', + self.type_selection_id.contact_type_other == 'c')) + if self.type_selection_id.partner_category_other: + domain.append( + ('category_id', 'in', + self.type_selection_id.partner_category_other.ids)) return { 'domain': { - 'other_partner_id': [('is_company', '=', is_company)], + 'other_partner_id': domain, } } + @api.onchange('this_partner_id') + def onchange_this_partner_id(self): + if not self.this_partner_id: + return {'domain': {'type_selection_id': []}} + return { + 'domain': { + 'type_selection_id': [ + '|', + ('contact_type_this', '=', False), + ('contact_type_this', '=', + 'c' if self.this_partner_id else 'p'), + '|', + ('partner_category_this', '=', False), + ('partner_category_this', 'in', + self.this_partner_id.category_id.ids), + ], + }, + } + @api.one def write(self, vals): """divert non-problematic writes to underlying table"""