Skip to content

Commit

Permalink
[REF] l10n_do_accounting: Refactoring funtion to V17
Browse files Browse the repository at this point in the history
  • Loading branch information
jorge-pcg authored and jose-pcg committed Feb 12, 2024
1 parent f2d1b73 commit 5e49928
Showing 1 changed file with 26 additions and 45 deletions.
71 changes: 26 additions & 45 deletions l10n_do_accounting/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,58 +99,39 @@ def write(self, vals):

@api.depends("vat", "country_id", "name")
def _compute_l10n_do_dgii_payer_type(self):

"""Compute the type of partner depending on soft decisions"""
company_id = self.env["res.company"].search(
[("id", "=", self.env.user.company_id.id)]
)
for partner in self:
vat = str(partner.vat if partner.vat else partner.name)
is_dominican_partner = bool(partner.country_id == self.env.ref("base.do"))
vat = partner.vat or partner.name
vat_len = len(vat)
startswith_4 = vat.startswith("4")
is_dominican_partner = partner.country_code == "DO"
upper_name = partner.name.upper()

if partner.country_id and not is_dominican_partner:
if not is_dominican_partner:
partner.l10n_do_dgii_tax_payer_type = "foreigner"

elif vat and (
not partner.l10n_do_dgii_tax_payer_type
or partner.l10n_do_dgii_tax_payer_type == "non_payer"
):
if partner.country_id and is_dominican_partner:
if vat.isdigit() and len(vat) == 9:
if not partner.vat:
partner.vat = vat
if partner.name and "MINISTERIO" in partner.name:
partner.l10n_do_dgii_tax_payer_type = "governmental"
elif partner.name and any(
[n for n in ("IGLESIA", "ZONA FRANCA") if n in partner.name]
):
partner.l10n_do_dgii_tax_payer_type = "special"
elif vat.startswith("1"):
partner.l10n_do_dgii_tax_payer_type = "taxpayer"
elif vat.startswith("4"):
partner.l10n_do_dgii_tax_payer_type = "nonprofit"
else:
partner.l10n_do_dgii_tax_payer_type = "taxpayer"

elif len(vat) == 11:
if vat.isdigit():
if not partner.vat:
partner.vat = vat
payer_type = (
"taxpayer"
if company_id.l10n_do_default_client == "fiscal"
else "non_payer"
)
partner.l10n_do_dgii_tax_payer_type = payer_type
else:
partner.l10n_do_dgii_tax_payer_type = "non_payer"
else:
elif is_dominican_partner and vat.isdigit():
if vat_len in (9, 11):
if vat_len == 11:
partner.l10n_do_dgii_tax_payer_type = "non_payer"
elif not partner.l10n_do_dgii_tax_payer_type:
partner.l10n_do_dgii_tax_payer_type = "non_payer"
elif "MINISTERIO" in upper_name and not startswith_4:
partner.l10n_do_dgii_tax_payer_type = "governmental"
elif "ZONA FRANCA" in upper_name:
partner.l10n_do_dgii_tax_payer_type = "special"
elif ("IGLESIA" in upper_name) or (
"MINISTERIO" in upper_name and startswith_4
):
partner.l10n_do_dgii_tax_payer_type = "special"
elif not startswith_4:
partner.l10n_do_dgii_tax_payer_type = "taxpayer"
else:
partner.l10n_do_dgii_tax_payer_type = "nonprofit"

else:
partner.l10n_do_dgii_tax_payer_type = "non_payer"
else:
partner.l10n_do_dgii_tax_payer_type = (
partner.l10n_do_dgii_tax_payer_type
)
partner.l10n_do_dgii_tax_payer_type = "non_payer"

def _inverse_l10n_do_dgii_tax_payer_type(self):
for partner in self:
Expand Down

0 comments on commit 5e49928

Please sign in to comment.