| 1 |
|
| 2 |
from odoo import models |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
UY_DOC_SUBTYPES = [ |
| 7 |
["0"], |
| 8 |
["101", "102", "103", "201", "202", "203"], |
| 9 |
["111", "112", "113", "211", "212", "213"], |
| 10 |
["121", "122", "123", "221", "222", "223"], |
| 11 |
["151", "152", "153", "251", "252", "253"], |
| 12 |
] |
| 13 |
|
| 14 |
|
| 15 |
class AccountMove(models.Model): |
| 16 |
_inherit = 'account.move' |
| 17 |
|
| 18 |
def _get_starting_sequence(self): |
| 19 |
""" If use documents then will create a new starting sequence using the document type code prefix and the |
| 20 |
journal document number with a 8 padding number """ |
| 21 |
if self.l10n_latam_use_documents and self.company_id.account_fiscal_country_id.code == "UY" and self.l10n_latam_document_type_id: |
| 22 |
return self._l10n_uy_get_formatted_sequence() |
| 23 |
return super()._get_starting_sequence() |
| 24 |
|
| 25 |
def _l10n_uy_get_formatted_sequence(self, number=0): |
| 26 |
return "%s A%07d" % (self.l10n_latam_document_type_id.doc_code_prefix, number) |
| 27 |
|
| 28 |
def _get_last_sequence_domain(self, relaxed=False): |
| 29 |
where_string, param = super(AccountMove, self)._get_last_sequence_domain(relaxed) |
| 30 |
if self.company_id.account_fiscal_country_id.code == "UY" and self.l10n_latam_use_documents: |
| 31 |
where_string += " AND l10n_latam_document_type_id = %(l10n_latam_document_type_id)s" |
| 32 |
param['l10n_latam_document_type_id'] = self.l10n_latam_document_type_id.id or 0 |
| 33 |
return where_string, param |
| 34 |
|
| 35 |
def _get_l10n_latam_documents_domain(self): |
| 36 |
""" If this is a reversal or debit, suggest only related subtypes """ |
| 37 |
self.ensure_one() |
| 38 |
domain = super()._get_l10n_latam_documents_domain() |
| 39 |
if self.country_code == "UY" and (original_move := self.reversed_entry_id or self.debit_origin_id): |
| 40 |
matching_subtype_codes = [ |
| 41 |
subtype for subtype in UY_DOC_SUBTYPES |
| 42 |
if original_move.l10n_latam_document_type_id.code in subtype |
| 43 |
] |
| 44 |
if matching_subtype_codes: |
| 45 |
|
| 46 |
codes = self.env["l10n_latam.document.type"].search(domain).mapped('code') |
| 47 |
allowed_codes = set(codes).intersection(set(matching_subtype_codes[0])) |
| 48 |
domain += [("code", "in", tuple(allowed_codes))] |
| 49 |
return domain |