[IMP] partner_profiles: remove position profiles from child_ids

This commit is contained in:
Stéphan Sainléger
2023-06-21 21:21:15 +02:00
parent 0f10de644e
commit 49f73b86a7
5 changed files with 22 additions and 9 deletions

View File

@@ -3,7 +3,7 @@
{
"name": "partner_profiles",
"version": "12.0.2.3.1",
"version": "12.0.2.4.0",
"author": "Elabore",
"website": "https://elabore.coop",
"maintainer": "Stéphan Sainléger",

View File

@@ -100,6 +100,12 @@ msgstr "Société"
msgid "Contact"
msgstr ""
#. module: partner_profiles
#: model:ir.model.fields,field_description:partner_profiles.field_res_partner__child_ids
#: model:ir.model.fields,field_description:partner_profiles.field_res_users__child_ids
msgid "Contacts"
msgstr ""
#. module: partner_profiles
#: model_terms:ir.ui.view,arch_db:partner_profiles.partner_profiles_form_view
msgid "Country"

View File

@@ -85,6 +85,12 @@ msgstr ""
msgid "Contact"
msgstr ""
#. module: partner_profiles
#: model:ir.model.fields,field_description:partner_profiles.field_res_partner__child_ids
#: model:ir.model.fields,field_description:partner_profiles.field_res_users__child_ids
msgid "Contacts"
msgstr ""
#. module: partner_profiles
#: model_terms:ir.ui.view,arch_db:partner_profiles.partner_profiles_form_view
msgid "Country"

View File

@@ -39,7 +39,9 @@ class res_partner(models.Model):
other_contact_ids = fields.One2many(
domain=[("is_position_profile", "=", True)]
)
child_ids = fields.One2many(
domain=[("is_position_profile", "=", False)]
)
structure_position_ids = fields.One2many('res.partner', 'parent_id', string="Structure's positions", domain=[('active', '=', True), ('is_position_profile', '=', True)])
@api.depends("partner_profile", "other_contact_ids")
@@ -87,7 +89,7 @@ class res_partner(models.Model):
def _onchange_is_company(self):
for partner in self:
if partner.is_main_profile:
if partner.has_position or partner.child_ids.filtered(lambda c: c.is_position_profile):
if partner.has_position or partner.structure_position_ids.filtered(lambda c: c.is_position_profile):
raise UserError("You can not modify the partner company type when the parner has postion profiles associated. Please remove the position profiles before retrying.")
if partner.public_profile_id:
# public_partner = self.env["res.partner"].browse(partner.public_profile_id)[0]
@@ -138,9 +140,8 @@ class res_partner(models.Model):
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()
for position in self.structure_position_ids:
position.unlink()
return super(res_partner, self).unlink()
@api.multi

View File

@@ -57,8 +57,8 @@
expr="//field[@name='child_ids']" position="before">
<div class="alert alert-info" role="alert" style="margin-bottom:0px;"
attrs="{'invisible': [('is_company','=', False)]}">
<span>Please find here <strong>all</strong> the profiles/addresses/contacts
linked to this main profile. Contact creation from this tab <strong>only
<span>Please find here <strong>all</strong> the addresses/contacts linked to
this main profile. Contact creation from this tab <strong>only
generates new main profiles</strong>.</span>
</div>
<div class="alert alert-info" role="alert" style="margin-bottom:0px;"