diff --git a/l10n_do_accounting/models/account_move.py b/l10n_do_accounting/models/account_move.py index 58b6f6ce8..b2dd71fb1 100644 --- a/l10n_do_accounting/models/account_move.py +++ b/l10n_do_accounting/models/account_move.py @@ -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')); + + 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'); + + 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') + AND l10n_latam_manual_document_number = 'f'); + """ + ) + return super()._auto_init() @api.model def _name_search( diff --git a/l10n_do_accounting/models/res_partner.py b/l10n_do_accounting/models/res_partner.py index 5ebd82e79..c23abca18 100644 --- a/l10n_do_accounting/models/res_partner.py +++ b/l10n_do_accounting/models/res_partner.py @@ -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): for partner in self: partner.l10n_do_dgii_tax_payer_type = partner.l10n_do_dgii_tax_payer_type diff --git a/l10n_do_accounting/views/account_journal_views.xml b/l10n_do_accounting/views/account_journal_views.xml index 2785a9066..f763a53ed 100644 --- a/l10n_do_accounting/views/account_journal_views.xml +++ b/l10n_do_accounting/views/account_journal_views.xml @@ -16,7 +16,7 @@ - +