Skip to content

Commit

Permalink
[WIP] l10n_do_accounting: don't create index
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-pcg committed Feb 12, 2024
1 parent bc94985 commit e5f85c6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 63 deletions.
26 changes: 13 additions & 13 deletions l10n_do_accounting/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
"data": [
"security/ir.model.access.csv",
"security/res_groups.xml",
"data/l10n_latam.document.type.csv",
"wizard/account_move_reversal_views.xml",
"wizard/account_move_cancel_views.xml",
"wizard/account_debit_note_views.xml",
"views/res_config_settings_view.xml",
"views/account_move_views.xml",
"views/res_partner_views.xml",
"views/res_company_views.xml",
"views/account_dgii_menuitem.xml",
"views/account_journal_views.xml",
"views/l10n_latam_document_type_views.xml",
"views/report_templates.xml",
"views/report_invoice.xml",
# "data/l10n_latam.document.type.csv",
# "wizard/account_move_reversal_views.xml",
# "wizard/account_move_cancel_views.xml",
# "wizard/account_debit_note_views.xml",
# "views/res_config_settings_view.xml",
# "views/account_move_views.xml",
# "views/res_partner_views.xml",
# "views/res_company_views.xml",
# "views/account_dgii_menuitem.xml",
# "views/account_journal_views.xml",
# "views/l10n_latam_document_type_views.xml",
# "views/report_templates.xml",
# "views/report_invoice.xml",
],
# only loaded in demonstration mode
"demo": [
Expand Down
100 changes: 50 additions & 50 deletions l10n_do_accounting/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,56 @@ 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.",
),
(
"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.",
),
]
# _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')

Check failure on line 167 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 167 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 = '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')

Check failure on line 172 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 172 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()

# def init(self):
# super(AccountMove, self).init()
Expand Down Expand Up @@ -173,39 +206,6 @@ def _get_l10n_do_income_type(self):
# )
# )

def _auto_init(self):
if not index_exists(
self.env.cr, "account_move_unique_l10n_do_fiscal_number_sales"
):
drop_index(
self.env.cr, "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()

@api.model
def _name_search(
self, name="", args=None, operator="ilike", limit=100, name_get_uid=None
Expand Down

0 comments on commit e5f85c6

Please sign in to comment.