Skip to content

Commit 05949e4

Browse files
committed
[IMP]account_background_post: Improves background post method to be able to receive the IDs to validate as an argument
1 parent 50ce5c5 commit 05949e4

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

account_background_post/models/account_move.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ def get_internal_partners(self):
1717
return res
1818

1919
@api.model
20-
def _cron_background_post_invoices(self, batch_size=20):
20+
def _cron_background_post_invoices(self, batch_size=20, ids=None):
2121
"""Busca las facturas que estan marcadas por ser validadas en background y las valida.
2222
2323
Ponemos un batch size para mejorar la performance ya que odoo econimiza muchas queries al tener
24-
un prefetch_ids de 20 en vez de 1. pero ademas, iteramos y no mandamos el atcion_post a todos los
25-
records juntos para no tener problemas frente a facturas con error y envio de emails o cosas similares
24+
un prefetch_ids de 20 en vez de 1. pero ademas, iteramos y no mandamos el action_post a todos los
25+
records juntos para no tener problemas frente a facturas con error y envio de emails o cosas similares.
26+
Argumentos:
27+
- batch_size: Cantidad maxima de facturas a validar en este llamado.
28+
- ids: Si se pasa una lista de ids desde el ir_cron, solo se procesan esos registros.
2629
"""
27-
moves = self.search([("background_post", "=", True), ("state", "=", "draft")])
30+
31+
if ids is not None:
32+
moves = self.browse(ids)
33+
else:
34+
moves = self.search([("background_post", "=", True), ("state", "=", "draft")])
2835

2936
for move in moves[:batch_size]:
3037
try:
@@ -41,7 +48,14 @@ def _cron_background_post_invoices(self, batch_size=20):
4148
body_is_html=True,
4249
)
4350
if len(moves) > batch_size:
44-
self.env.ref("account_background_post.ir_cron_background_post_invoices")._trigger()
51+
52+
cron_id = self.env.context.get('cron_id')
53+
if cron_id:
54+
#Si tenemos cron_id en el contexto, usamos ese para relanzar la ejecucion.
55+
self.env['ir.cron'].browse(self.env.context['cron_id'])._trigger()
56+
return
57+
self.env.ref('account_background_post.ir_cron_background_post_invoices')._trigger()
58+
4559

4660
def _post(self, soft=True):
4761
posted = super()._post(soft=soft)

0 commit comments

Comments
 (0)