Debian Codegraph @

addons/l10n_sa_edi/models/account_edi_document.py

raw
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4
5 from odoo import models
6
7
8 class AccountEdiDocument(models.Model):
9 _inherit = 'account.edi.document'
10
11 def _prepare_jobs(self):
12 """
13 Override to achieve the following:
14
15 If there is a job to process that may already be part of the chain (posted invoice that timed out),
16 Moves it at the beginning of the list.
17 """
18 jobs = super()._prepare_jobs()
19 if len(jobs) > 1:
20 move_first_index = 0
21 for index, job in enumerate(jobs):
22 documents = job['documents']
23 if any(d.edi_format_id.code == 'sa_zatca' and d.state == 'to_send' and d.move_id.l10n_sa_chain_index for d in documents):
24 move_first_index = index
25 break
26 jobs = [jobs[move_first_index]] + jobs[:move_first_index] + jobs[move_first_index + 1:]
27
28 return jobs