| 1 |
|
| 2 |
|
| 3 |
from odoo import fields, models, api, _ |
| 4 |
from odoo.exceptions import ValidationError |
| 5 |
|
| 6 |
|
| 7 |
class AccountJournal(models.Model): |
| 8 |
_inherit = "account.journal" |
| 9 |
|
| 10 |
l10n_latam_use_documents = fields.Boolean( |
| 11 |
'Use Documents?', help="If active: will be using for legal invoicing (invoices, debit/credit notes)." |
| 12 |
" If not set means that will be used to register accounting entries not related to invoicing legal documents." |
| 13 |
" For Example: Receipts, Tax Payments, Register journal entries") |
| 14 |
l10n_latam_company_use_documents = fields.Boolean(compute='_compute_l10n_latam_company_use_documents') |
| 15 |
|
| 16 |
@api.depends('company_id') |
| 17 |
def _compute_l10n_latam_company_use_documents(self): |
| 18 |
for rec in self: |
| 19 |
rec.l10n_latam_company_use_documents = rec.company_id._localization_use_documents() |
| 20 |
|
| 21 |
@api.onchange('company_id', 'type') |
| 22 |
def _onchange_company(self): |
| 23 |
self.l10n_latam_use_documents = self.type in ['sale', 'purchase'] and \ |
| 24 |
self.l10n_latam_company_use_documents |
| 25 |
|
| 26 |
def _compute_has_sequence_holes(self): |
| 27 |
use_documents_journals = self.filtered(lambda j: j.l10n_latam_use_documents) |
| 28 |
use_documents_journals.has_sequence_holes = False |
| 29 |
if other_journals := self - use_documents_journals: |
| 30 |
super(AccountJournal, other_journals)._compute_has_sequence_holes() |
| 31 |
|
| 32 |
@api.constrains('l10n_latam_use_documents') |
| 33 |
def check_use_document(self): |
| 34 |
for rec in self: |
| 35 |
if rec.env['account.move'].search_count([('journal_id', '=', rec.id), ('posted_before', '=', True)], limit=1): |
| 36 |
raise ValidationError(_( |
| 37 |
'You can not modify the field "Use Documents?" if there are validated invoices in this journal!')) |
| 38 |
|
| 39 |
@api.depends('type', 'l10n_latam_use_documents') |
| 40 |
def _compute_debit_sequence(self): |
| 41 |
super()._compute_debit_sequence() |
| 42 |
for journal in self: |
| 43 |
if journal.l10n_latam_use_documents: |
| 44 |
journal.debit_sequence = False |
| 45 |
|
| 46 |
@api.depends('type', 'l10n_latam_use_documents') |
| 47 |
def _compute_refund_sequence(self): |
| 48 |
super()._compute_refund_sequence() |
| 49 |
for journal in self: |
| 50 |
if journal.l10n_latam_use_documents: |
| 51 |
journal.refund_sequence = False |