Browse Source

allow same partner on both sides of a relation

* add boolean field `ResPartnerRelationType.allow_self`
* add related field `ResPartnerRelation.allow_self`
pull/145/head
Charbel Jacquin 9 years ago
parent
commit
d1bfa4b4b7
  1. 2
      partner_relations/model/res_partner_relation.py
  2. 3
      partner_relations/model/res_partner_relation_type.py
  3. 2
      partner_relations/view/res_partner_relation_type.xml

2
partner_relations/model/res_partner_relation.py

@ -82,6 +82,7 @@ class ResPartnerRelation(models.Model):
),
}
allow_self = fields.Boolean(related='type_id.allow_self')
left_contact_type = fields.Selection(
lambda s: s.env['res.partner.relation.type']._get_partner_types(),
'Left Partner Type',
@ -287,6 +288,7 @@ class ResPartnerRelation(models.Model):
:raises exceptions.Warning: When constraint is violated
"""
if self.left_partner_id == self.right_partner_id:
if not self.allow_self:
raise exceptions.Warning(
_('Partners cannot have a relation with themselves.')
)

3
partner_relations/model/res_partner_relation_type.py

@ -57,6 +57,9 @@ class ResPartnerRelationType(models.Model):
'res.partner.category',
'Right partner category',
)
allow_self = fields.Boolean(
'Allow both sides to be the same'
)
@api.model
def _get_partner_types(self):

2
partner_relations/view/res_partner_relation_type.xml

@ -9,6 +9,7 @@
<field name="name_inverse" />
<field name="contact_type_left" />
<field name="contact_type_right" />
<field name="allow_self" />
</tree>
</field>
</record>
@ -19,6 +20,7 @@
<form version="7.0" string="Partner relation">
<sheet>
<group>
<field name="allow_self" />
<group
colspan="2" col="2"
string="Left side of relation"

Loading…
Cancel
Save