[IMP] l10n_latam_invoice_document: add all in the domain
For BR the same document type can be used for credit notes, debit notes and regular invoices. There was no way to indicate that in the internal_type field of the document type, so we wanted to add it in the main module for simplicity. Part-of: odoo/odoo#135959
This commit is contained in:
@@ -193,27 +193,24 @@ class AccountMove(models.Model):
|
||||
|
||||
def _get_l10n_latam_documents_domain(self):
|
||||
self.ensure_one()
|
||||
if self.move_type in ['out_refund', 'in_refund']:
|
||||
invoice_type = self.move_type
|
||||
if invoice_type in ['out_refund', 'in_refund']:
|
||||
internal_types = ['credit_note']
|
||||
else:
|
||||
elif invoice_type in ['out_invoice', 'in_invoice']:
|
||||
internal_types = ['invoice', 'debit_note']
|
||||
if self.debit_origin_id:
|
||||
internal_types = ['debit_note']
|
||||
internal_types += ['all']
|
||||
return [('internal_type', 'in', internal_types), ('country_id', '=', self.company_id.account_fiscal_country_id.id)]
|
||||
|
||||
@api.depends('journal_id', 'partner_id', 'company_id', 'move_type')
|
||||
@api.depends('journal_id', 'partner_id', 'company_id', 'move_type', 'debit_origin_id')
|
||||
def _compute_l10n_latam_available_document_types(self):
|
||||
self.l10n_latam_available_document_type_ids = False
|
||||
for rec in self.filtered(lambda x: x.journal_id and x.l10n_latam_use_documents and x.partner_id):
|
||||
rec.l10n_latam_available_document_type_ids = self.env['l10n_latam.document.type'].search(rec._get_l10n_latam_documents_domain())
|
||||
|
||||
@api.depends('l10n_latam_available_document_type_ids', 'debit_origin_id')
|
||||
@api.depends('l10n_latam_available_document_type_ids')
|
||||
def _compute_l10n_latam_document_type(self):
|
||||
for rec in self.filtered(lambda x: x.state == 'draft'):
|
||||
document_types = rec.l10n_latam_available_document_type_ids._origin
|
||||
invoice_type = rec.move_type
|
||||
if invoice_type in ['out_refund', 'in_refund']:
|
||||
document_types = document_types.filtered(lambda x: x.internal_type not in ['debit_note', 'invoice'])
|
||||
elif invoice_type in ['out_invoice', 'in_invoice']:
|
||||
document_types = document_types.filtered(lambda x: x.internal_type not in ['credit_note'])
|
||||
if rec.debit_origin_id:
|
||||
document_types = document_types.filtered(lambda x: x.internal_type == 'debit_note')
|
||||
rec.l10n_latam_document_type_id = document_types and document_types[0].id
|
||||
|
||||
@@ -23,7 +23,7 @@ class L10nLatamDocumentType(models.Model):
|
||||
code = fields.Char(help='Code used by different localizations')
|
||||
report_name = fields.Char('Name on Reports', help='Name that will be printed in reports, for example "CREDIT NOTE"', translate=True)
|
||||
internal_type = fields.Selection(
|
||||
[('invoice', 'Invoices'), ('debit_note', 'Debit Notes'), ('credit_note', 'Credit Notes')],
|
||||
[('invoice', 'Invoices'), ('debit_note', 'Debit Notes'), ('credit_note', 'Credit Notes'), ('all', 'All Documents')],
|
||||
help='Analog to odoo account.move.move_type but with more options allowing to identify the kind of document we are'
|
||||
' working with. (not only related to account.move, could be for documents of other models like stock.picking)')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user