Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G2P-2707: ID Deduplication: Remove ID Type from config when deleted #31

Merged
merged 4 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 0 additions & 110 deletions g2p_registration_portal_user/i18n/g2p_registration_portal_user.pot

This file was deleted.

4 changes: 2 additions & 2 deletions g2p_registry_id_deduplication/models/registrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from odoo import _, fields, models
from odoo.exceptions import UserError
from odoo.tools import safe_eval

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -108,8 +109,7 @@ def get_id_types_with_kind(self, id_field, is_group):
ir_config = self.env["ir.config_parameter"].sudo()
id_type_ids_str = ir_config.get_param(f"g2p_registry_id_deduplication.{id_field}", default=None)

id_type_ids = id_type_ids_str.strip("][").split(", ") if id_type_ids_str is not None else [""]
id_type_ids = id_type_ids if len(id_type_ids[0]) != 0 else []
id_type_ids = safe_eval.safe_eval(id_type_ids_str)

if len(id_type_ids) < 1:
raise UserError(_("Deduplication is not configured"))
Expand Down
26 changes: 26 additions & 0 deletions g2p_registry_id_deduplication/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,29 @@ def get_values(self):
else None,
)
return res


class G2PIDType(models.Model):
_inherit = "g2p.id.type"

def unlink(self):
ids_to_delete = self.ids

res = super().unlink()

ir_config = self.env["ir.config_parameter"].sudo()
ind_id_types_param = ir_config.get_param(
"g2p_registry_id_deduplication.ind_deduplication_id_types_ids"
)

if ind_id_types_param:
ind_id_types_ids = safe_eval.safe_eval(ind_id_types_param)
updated_ind_id_types_ids = [
id_type for id_type in ind_id_types_ids if id_type not in ids_to_delete
]
ir_config.set_param(
"g2p_registry_id_deduplication.ind_deduplication_id_types_ids",
updated_ind_id_types_ids,
)

return res
Loading