From 2323966102d0c8835a84732e8706d6c32d541bfb Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Thu, 13 Jun 2024 16:57:49 +0200 Subject: [PATCH] [FIX] l10n_be_cooperator_national_number: Allow removal of national number Signed-off-by: Carmen Bianca BAKKER --- .../models/res_partner.py | 26 ++++++++++--------- .../readme/newsfragments/139.bugfix.rst | 1 + 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 l10n_be_cooperator_national_number/readme/newsfragments/139.bugfix.rst diff --git a/l10n_be_cooperator_national_number/models/res_partner.py b/l10n_be_cooperator_national_number/models/res_partner.py index 47550c8d2..bbb85953e 100644 --- a/l10n_be_cooperator_national_number/models/res_partner.py +++ b/l10n_be_cooperator_national_number/models/res_partner.py @@ -35,18 +35,20 @@ def get_be_national_register_number(self): def update_belgian_national_number(self, national_number): self.ensure_one() result = None - if national_number: - existing = self.get_be_national_register_number_id_number() - # Update - if existing: + existing = self.get_be_national_register_number_id_number() + # Update + if existing: + if not national_number: + existing.unlink() + else: existing.name = national_number result = existing - # Create new - else: - values = { - "name": national_number, - "category_id": self.get_be_national_register_number_id_category().id, - "partner_id": self.id, - } - result = self.env["res.partner.id_number"].create(values) + # Create new + elif national_number: + values = { + "name": national_number, + "category_id": self.get_be_national_register_number_id_category().id, + "partner_id": self.id, + } + result = self.env["res.partner.id_number"].create(values) return result diff --git a/l10n_be_cooperator_national_number/readme/newsfragments/139.bugfix.rst b/l10n_be_cooperator_national_number/readme/newsfragments/139.bugfix.rst new file mode 100644 index 000000000..8ba83511f --- /dev/null +++ b/l10n_be_cooperator_national_number/readme/newsfragments/139.bugfix.rst @@ -0,0 +1 @@ +Allow removal of national number.