account_journal.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. from odoo import fields, models, api, _
  3. from odoo.exceptions import ValidationError
  4. class AccountJournal(models.Model):
  5. _inherit = "account.journal"
  6. l10n_latam_use_documents = fields.Boolean(
  7. 'Use Documents?', help="If active: will be using for legal invoicing (invoices, debit/credit notes)."
  8. " If not set means that will be used to register accounting entries not related to invoicing legal documents."
  9. " For Example: Receipts, Tax Payments, Register journal entries")
  10. l10n_latam_company_use_documents = fields.Boolean(compute='_compute_l10n_latam_company_use_documents')
  11. @api.depends('company_id')
  12. def _compute_l10n_latam_company_use_documents(self):
  13. for rec in self:
  14. rec.l10n_latam_company_use_documents = rec.company_id._localization_use_documents()
  15. @api.onchange('company_id', 'type')
  16. def _onchange_company(self):
  17. self.l10n_latam_use_documents = self.type in ['sale', 'purchase'] and \
  18. self.l10n_latam_company_use_documents
  19. @api.constrains('l10n_latam_use_documents')
  20. def check_use_document(self):
  21. for rec in self:
  22. if rec.env['account.move'].search([('journal_id', '=', rec.id), ('posted_before', '=', True)], limit=1):
  23. raise ValidationError(_(
  24. 'You can not modify the field "Use Documents?" if there are validated invoices in this journal!'))
  25. @api.onchange('type', 'l10n_latam_use_documents')
  26. def _onchange_type(self):
  27. res = super()._onchange_type()
  28. if self.l10n_latam_use_documents:
  29. self.refund_sequence = False
  30. return res