| 1 |
from odoo import _, api, models |
| 2 |
from odoo.exceptions import UserError |
| 3 |
|
| 4 |
l10n_tr_official_code_categories = [ |
| 5 |
"res_partner_category_hizmetno", |
| 6 |
"res_partner_category_mersisno", |
| 7 |
"res_partner_category_tesisatno", |
| 8 |
"res_partner_category_telefonno", |
| 9 |
"res_partner_category_distributorno", |
| 10 |
"res_partner_category_ticaretsicilno", |
| 11 |
"res_partner_category_tapdkno", |
| 12 |
"res_partner_category_bayino", |
| 13 |
"res_partner_category_aboneno", |
| 14 |
"res_partner_category_sayacno", |
| 15 |
"res_partner_category_epdkno", |
| 16 |
"res_partner_category_subeno", |
| 17 |
"res_partner_category_pasaportno", |
| 18 |
"res_partner_category_ureticino", |
| 19 |
"res_partner_category_ciftcino", |
| 20 |
"res_partner_category_imalatcino", |
| 21 |
"res_partner_category_dosyano", |
| 22 |
"res_partner_category_hastano", |
| 23 |
"res_partner_category_musterino", |
| 24 |
"res_partner_category_aracikurumvkn", |
| 25 |
"res_partner_category_aracikurumetiket", |
| 26 |
] |
| 27 |
|
| 28 |
l10n_tr_official_mandatory_code_categories = [ |
| 29 |
"res_partner_category_mersisno", |
| 30 |
"res_partner_category_ticaretsicilno", |
| 31 |
] |
| 32 |
|
| 33 |
|
| 34 |
class PartnerCategory(models.Model): |
| 35 |
_inherit = "res.partner.category" |
| 36 |
|
| 37 |
def _get_categories_from_xml_ids(self, xml_ids_list): |
| 38 |
categories = self.env["res.partner.category"] |
| 39 |
for xml_id in xml_ids_list: |
| 40 |
categories |= self.env.ref(f"l10n_tr_nilvera_einvoice.{xml_id}", raise_if_not_found=False) |
| 41 |
return categories |
| 42 |
|
| 43 |
def _get_l10n_tr_official_categories(self): |
| 44 |
return self._get_categories_from_xml_ids(l10n_tr_official_code_categories) |
| 45 |
|
| 46 |
def _get_l10n_tr_official_mandatory_categories(self): |
| 47 |
return self._get_categories_from_xml_ids(l10n_tr_official_mandatory_code_categories) |
| 48 |
|
| 49 |
@api.ondelete(at_uninstall=False) |
| 50 |
def _unlink_l10n_tr_official_category(self): |
| 51 |
"""Prevent the deletion of Nilvera official TR categories""" |
| 52 |
official_categories = self._get_l10n_tr_official_categories() |
| 53 |
if any(rec in official_categories for rec in self): |
| 54 |
raise UserError(_("The Contact Tag(s) cannot be deleted because it is used in Türkiye electronic integrations.")) |