account_edi_format.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. # -*- coding:utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import models
  4. class AccountEdiFormat(models.Model):
  5. _inherit = 'account.edi.format'
  6. def _l10n_it_invoice_is_direct(self, invoice):
  7. """ An invoice is only direct if the Transport Documents are all done the same day as the invoice. """
  8. for ddt in invoice.l10n_it_ddt_ids:
  9. if not ddt.date_done or ddt.date_done != invoice.invoice_date:
  10. return False
  11. return True
  12. def _l10n_it_get_invoice_features_for_document_type_selection(self, invoice):
  13. res = super()._l10n_it_get_invoice_features_for_document_type_selection(invoice)
  14. res['direct_invoice'] = self._l10n_it_invoice_is_direct(invoice)
  15. return res
  16. def _l10n_it_document_type_mapping(self):
  17. """ Deferred invoices (not direct) require TD24 FatturaPA Document Type. """
  18. res = super()._l10n_it_document_type_mapping()
  19. for document_type, infos in res.items():
  20. if document_type == 'TD07':
  21. continue
  22. infos['direct_invoice'] = True
  23. res['TD24'] = dict(move_types=['out_invoice'], import_type='in_invoice', direct_invoice=False)
  24. return res