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

[17.0][REF] l10n_do_accounting: Refactoring funtion to V17 #1136

Merged
merged 1 commit into from
Feb 12, 2024
Merged
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
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
Loading