[IMP] partner_profiles: prevent company type edit in several cases

Prevents the modification of the company type of res.partner:
- if partner is a public or a position profile
- if the partner has position profiles attached

Also synchronize the company type between main and public profiles.
This commit is contained in:
Stéphan Sainléger
2023-05-19 14:31:39 +02:00
parent 7fbbb4f396
commit dd184128af
2 changed files with 18 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
import logging
from odoo import _, api, fields, models
from odoo.exceptions import UserError
_logger = logging.getLogger(__name__)
@@ -80,6 +81,19 @@ class res_partner(models.Model):
self.contact_type = "attached"
self.partner_profile = position_profile.id
@api.onchange("is_company")
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):
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]
values = {
"is_company": partner.is_company,
}
partner.public_profile_id.sudo().write(values)
@api.model
def create(self, vals):
"""Assume if not type, default is contact"""

View File

@@ -95,6 +95,10 @@
<attribute name="attrs">{'invisible': ['|', ('is_public_profile','=', True),
('is_position_profile','=', True)]}</attribute>
</xpath>
<xpath expr="//field[@name='company_type']" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('is_public_profile','=', True),
('is_position_profile','=', True)]}</attribute>
</xpath>
<xpath expr="//field[@name='image']" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('is_public_profile','=', True),
('is_position_profile','=', True)]}</attribute>