Files
odoo_source/addons/account_edi/models/account_journal.py
T
Benjamin Frantzen (bfr) fbc77a6ecd [FIX] account_edi: a failed import of an attachment with account_edi now allows OCR to run automatically.
Before this commit, account_invoice_extract and account_edi where independent in parsing files uploaded or added as attachment in an invoice. Some tricks where used to avoid clash, but they were not perfect and some bugs appeared like the OCR not triggering automatically or an attachment being parsed twice by account_edi when parsing failed. The goal of this commit is to unify the import of files between the two features and ensure that they will not clash.

For more information about potential problems that appeared before :
See https://github.com/odoo/odoo/pull/61169
See https://github.com/odoo/enterprise/pull/15124/

closes odoo/odoo#65660

X-original-commit: 8435d0e8990509ee67425977f970ab27bea8133a
Related: odoo/enterprise#16172
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Signed-off-by: bfr-o <bfr-o@users.noreply.github.com>
2021-02-05 17:56:12 +00:00

54 lines
2.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models, fields, _
from odoo.exceptions import UserError
class AccountJournal(models.Model):
_inherit = 'account.journal'
edi_format_ids = fields.Many2many(comodel_name='account.edi.format',
string='Electronic invoicing',
help='Send XML/EDI invoices',
domain="[('id', 'in', compatible_edi_ids)]",
compute='_compute_edi_format_ids',
readonly=False, store=True)
compatible_edi_ids = fields.Many2many(comodel_name='account.edi.format',
compute='_compute_compatible_edi_ids',
help='EDI format that support moves in this journal')
def write(self, vals):
# OVERRIDE
# Don't allow the user to deactivate an edi format having at least one document to be processed.
if vals.get('edi_format_ids'):
old_edi_format_ids = self.edi_format_ids
res = super().write(vals)
diff_edi_format_ids = old_edi_format_ids - self.edi_format_ids
documents = self.env['account.edi.document'].search([
('move_id.journal_id', 'in', self.ids),
('edi_format_id', 'in', diff_edi_format_ids.ids),
('state', 'in', ('to_cancel', 'to_send')),
])
if documents:
raise UserError(_('Cannot deactivate (%s) on this journal because not all documents are synchronized', ', '.join(documents.edi_format_id.mapped('display_name'))))
return res
else:
return super().write(vals)
@api.depends('type', 'company_id', 'company_id.country_id')
def _compute_compatible_edi_ids(self):
edi_formats = self.env['account.edi.format'].search([])
for journal in self:
compatible_edis = edi_formats.filtered(lambda e: e._is_compatible_with_journal(journal))
journal.compatible_edi_ids += compatible_edis
@api.depends('type', 'company_id', 'company_id.country_id')
def _compute_edi_format_ids(self):
edi_formats = self.env['account.edi.format'].search([])
for journal in self:
journal.edi_format_ids += edi_formats.filtered(lambda e: e._is_compatible_with_journal(journal))