Skip to content

Commit

Permalink
[WIP] l10n_do_accounting: v17 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-pcg committed May 15, 2024
1 parent 264b390 commit 2d2c6df
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 101 deletions.
132 changes: 51 additions & 81 deletions l10n_do_accounting/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,87 +124,57 @@ def _get_l10n_do_income_type(self):
"manually because a new expiration date was set on journal",
)

# _sql_constraints = [
# (
# "unique_l10n_do_fiscal_number_sales",
# "",
# "Another document with the same fiscal number already exists.",
# ),
# (
# "account_move_unique_l10n_do_fiscal_number_purchase_manual",
# "",
# "Another document for the same partner with the same fiscal number already exists.",
# ),
# (
# "unique_l10n_do_fiscal_number_purchase_internal",
# "",
# "Another document for the same partner with the same fiscal number already exists.",
# ),
# ]

# def _auto_init(self):
# if not index_exists(
# self.env.cr, "account_move_unique_l10n_do_fiscal_number_sales"
# ):
# drop_index(
# self.env.cr, "account_move_unique_l10n_do_fiscal_number_purchase_manual", self._table
# )
# drop_index(
# self.env.cr,
# "unique_l10n_do_fiscal_number_purchase_internal",
# self._table,
# )
# self.env.cr.execute(
# """
# CREATE UNIQUE INDEX account_move_unique_l10n_do_fiscal_number_sales
# ON account_move(l10n_do_fiscal_number, company_id)
# WHERE (state = 'posted'
# AND (l10n_latam_document_type_id IS NOT NULL
# AND move_type NOT IN ('in_invoice', 'in_refund', 'in_receipt')));
# CREATE UNIQUE INDEX unique_l10n_do_fiscal_number_purchase_manual
# ON account_move(l10n_do_fiscal_number, commercial_partner_id, company_id)
# WHERE (state = 'posted'
# AND (l10n_latam_document_type_id IS NOT NULL AND move_type IN ('in_invoice', 'in_refund', 'in_receipt')
# AND l10n_latam_manual_document_number = 't'));
# CREATE UNIQUE INDEX unique_l10n_do_fiscal_number_purchase_internal
# ON account_move(l10n_do_fiscal_number, company_id)
# WHERE (state = 'posted'
# AND (l10n_latam_document_type_id IS NOT NULL AND move_type IN ('in_invoice', 'in_refund', 'in_receipt')
# AND l10n_latam_manual_document_number = 'f'));
# """
# )
# return super()._auto_init()

# def init(self):
# super(AccountMove, self).init()
#
# if not self._abstract and self._sequence_index:
# index_name = self._table + "_l10n_do_sequence_index"
# self.env.cr.execute(
# "SELECT indexname FROM pg_indexes WHERE indexname = %s", (index_name,)
# )
# if not self.env.cr.fetchone():
# self.env.cr.execute(
# sql.SQL(
# """
# CREATE INDEX {index_name} ON {table}
# ({sequence_index},
# l10n_do_sequence_prefix desc,
# l10n_do_sequence_number desc,
# {field});
# CREATE INDEX {index2_name} ON {table}
# ({sequence_index},
# id desc,
# l10n_do_sequence_prefix);
# """
# ).format(
# sequence_index=sql.Identifier(self._sequence_index),
# index_name=sql.Identifier(index_name),
# index2_name=sql.Identifier(index_name + "2"),
# table=sql.Identifier(self._table),
# field=sql.Identifier(self._l10n_do_sequence_field),
# )
# )
_sql_constraints = [
(
"unique_l10n_do_fiscal_number_sales",
"",
"Another document with the same fiscal number already exists.",
),
(
"unique_l10n_do_fiscal_number_purchase_manual",
"",
"Another document for the same partner with the same fiscal number already exists.",
),
(
"unique_l10n_do_fiscal_number_purchase_internal",
"",
"Another document for the same partner with the same fiscal number already exists.",
),
]

def _auto_init(self):
if not index_exists(
self.env.cr, "account_move_unique_l10n_do_fiscal_number_sales"
):
drop_index(
self.env.cr,
"account_move_unique_l10n_do_fiscal_number_purchase_manual",
self._table,
)
drop_index(
self.env.cr,
"account_move_unique_l10n_do_fiscal_number_purchase_internal",
self._table,
)
self.env.cr.execute(
"""
CREATE UNIQUE INDEX account_move_unique_l10n_do_fiscal_number_sales
ON account_move(l10n_do_fiscal_number, company_id)
WHERE (l10n_latam_document_type_id IS NOT NULL
AND move_type NOT IN ('in_invoice', 'in_refund'));

Check warning on line 165 in l10n_do_accounting/models/account_move.py

View workflow job for this annotation

GitHub Actions / flake8

blank line contains whitespace

Check warning on line 165 in l10n_do_accounting/models/account_move.py

View workflow job for this annotation

GitHub Actions / flake8

blank line contains whitespace
CREATE UNIQUE INDEX account_move_unique_l10n_do_fiscal_number_purchase_manual
ON account_move(l10n_do_fiscal_number, commercial_partner_id, company_id)
WHERE (l10n_latam_document_type_id IS NOT NULL AND move_type IN ('in_invoice', 'in_refund')
AND l10n_latam_manual_document_number = 't');

Check warning on line 170 in l10n_do_accounting/models/account_move.py

View workflow job for this annotation

GitHub Actions / flake8

blank line contains whitespace

Check warning on line 170 in l10n_do_accounting/models/account_move.py

View workflow job for this annotation

GitHub Actions / flake8

blank line contains whitespace
CREATE UNIQUE INDEX account_move_unique_l10n_do_fiscal_number_purchase_internal
ON account_move(l10n_do_fiscal_number, company_id)
WHERE (l10n_latam_document_type_id IS NOT NULL AND move_type IN ('in_invoice', 'in_refund', 'in_receipt')

Check failure on line 173 in l10n_do_accounting/models/account_move.py

View workflow job for this annotation

GitHub Actions / flake8

line too long (121 > 120 characters)

Check failure on line 173 in l10n_do_accounting/models/account_move.py

View workflow job for this annotation

GitHub Actions / flake8

line too long (121 > 120 characters)
AND l10n_latam_manual_document_number = 'f');
"""
)
return super()._auto_init()

@api.model
def _name_search(
Expand Down
37 changes: 18 additions & 19 deletions l10n_do_accounting/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,35 +103,34 @@ def _compute_l10n_do_dgii_payer_type(self):
for partner in self:
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()
is_dominican_partner = partner.country_code == "DO"

if not is_dominican_partner:
partner.l10n_do_dgii_tax_payer_type = "foreigner"
continue

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 "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"
if not vat.isdigit():
partner.l10n_do_dgii_tax_payer_type = "non_payer"
continue

if vat_len == 11:
partner.l10n_do_dgii_tax_payer_type = "non_payer"
elif vat_len == 9:
if "MINISTERIO" in upper_name and not vat.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 vat.startswith("4")):
partner.l10n_do_dgii_tax_payer_type = "special"
elif not vat.startswith("4"):
partner.l10n_do_dgii_tax_payer_type = "taxpayer"
else:
partner.l10n_do_dgii_tax_payer_type = "non_payer"
partner.l10n_do_dgii_tax_payer_type = "nonprofit"
else:
partner.l10n_do_dgii_tax_payer_type = "non_payer"


def _inverse_l10n_do_dgii_tax_payer_type(self):

Check failure on line 134 in l10n_do_accounting/models/res_partner.py

View workflow job for this annotation

GitHub Actions / flake8

too many blank lines (2)

Check failure on line 134 in l10n_do_accounting/models/res_partner.py

View workflow job for this annotation

GitHub Actions / flake8

too many blank lines (2)
for partner in self:
partner.l10n_do_dgii_tax_payer_type = partner.l10n_do_dgii_tax_payer_type
2 changes: 1 addition & 1 deletion l10n_do_accounting/views/account_journal_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<field name="l10n_do_document_type_ids" nolabel="1" colspan="2">
<tree create="false" delete="false" editable="top"
default_order="l10n_latam_document_type_id">
<field name="journal_id" invisible="1"/>
<field name="journal_id" column_invisible="True"/>
<field name="l10n_latam_document_type_id"/>
<field name="l10n_do_ncf_expiration_date"/>
</tree>
Expand Down

0 comments on commit 2d2c6df

Please sign in to comment.