[IMP] partner_profiles: delete profiles when main partner deleted
When a main partner is unlinked, all the linked profiles (public profile and position profiles) are deleted.
This commit is contained in:
committed by
Stéphan Sainléger
parent
6e227a83d4
commit
2e63b1216f
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "partner_profiles",
|
"name": "partner_profiles",
|
||||||
"version": "12.0.1.1.0",
|
"version": "12.0.1.2.0",
|
||||||
"author": "Elabore",
|
"author": "Elabore",
|
||||||
"website": "https://elabore.coop",
|
"website": "https://elabore.coop",
|
||||||
"maintainer": "Stéphan Sainléger",
|
"maintainer": "Stéphan Sainléger",
|
||||||
|
@@ -18,6 +18,7 @@ class res_partner(models.Model):
|
|||||||
translate=False,
|
translate=False,
|
||||||
readonly=False,
|
readonly=False,
|
||||||
)
|
)
|
||||||
|
contact_id = fields.Many2one(ondelete="cascade")
|
||||||
is_main_profile = fields.Boolean(compute="_compute_profile_booleans", store=True)
|
is_main_profile = fields.Boolean(compute="_compute_profile_booleans", store=True)
|
||||||
is_public_profile = fields.Boolean(compute="_compute_profile_booleans", store=True)
|
is_public_profile = fields.Boolean(compute="_compute_profile_booleans", store=True)
|
||||||
is_position_profile = fields.Boolean(
|
is_position_profile = fields.Boolean(
|
||||||
@@ -31,7 +32,6 @@ class res_partner(models.Model):
|
|||||||
compute="_compute_public_profile_id",
|
compute="_compute_public_profile_id",
|
||||||
string="Public profile",
|
string="Public profile",
|
||||||
store=True,
|
store=True,
|
||||||
ondelete="cascade",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# If current partner is Main partner, this field indicates what its position profiles are.
|
# If current partner is Main partner, this field indicates what its position profiles are.
|
||||||
@@ -117,6 +117,16 @@ class res_partner(models.Model):
|
|||||||
res = super(res_partner, self).create(vals)
|
res = super(res_partner, self).create(vals)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def unlink(self):
|
||||||
|
for partner in self:
|
||||||
|
if partner.is_company:
|
||||||
|
# Delete position profiles linked to the company main profile
|
||||||
|
child_ids = self.env["res.partner"].search([("parent_id", "=", partner.id), ("is_position_profile", "=", True)])
|
||||||
|
for child in child_ids:
|
||||||
|
child.unlink()
|
||||||
|
return super(res_partner, self).unlink()
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def search_position_partners(self, profile):
|
def search_position_partners(self, profile):
|
||||||
if profile:
|
if profile:
|
||||||
|
Reference in New Issue
Block a user