Skip to content

Commit

Permalink
[FIX] account_background_post: Add validation to bypass the validate_…
Browse files Browse the repository at this point in the history
…move method when running a test and run the original method of odoo
  • Loading branch information
rov-adhoc committed Sep 24, 2024
1 parent af43b31 commit aac4699
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions account_background_post/wizards/validate_account_move.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import _, api, fields, models
from odoo import _, api, fields, models, tools
from odoo.exceptions import UserError
import logging

Expand All @@ -24,6 +24,8 @@ def compute_force_background(self):
@api.model
def default_get(self, fields):
res = super().default_get(fields)
if tools.config['test_enable']:
return res

if self._context.get('active_model') == 'account.move':
domain = [('id', 'in', self._context.get('active_ids', [])), ('state', '=', 'draft')]
Expand All @@ -45,7 +47,7 @@ def action_background_post(self):
self.env.ref('account_background_post.ir_cron_background_post_invoices')._trigger()

def validate_move(self):
""" Sobre escribimos este metodo por completo para hacer:
""" Sobre escribimos este metodo si no se trata de un test por completo para hacer:
1. Que en lugar de hacer un _post hacemos un _action_post. esto porque odoo hace cosas como lanzar acciones y correr validaciones solo cuando corremos el action_post. y nosotros queremos que esas se apliquen. eso incluye el envio de email cuando validamos la factura.
Expand All @@ -55,6 +57,8 @@ def validate_move(self):
3. Limitamos sui el usuario quiere validar mas facturas que el batch size definido directamente
le pedimos que las valide en background. """

if tools.config['test_enable']:
return super().validate_move()
if self.count_inv > self.batch_size:
raise UserError(_('You can only validate on batches of size < %s invoices. If you need to validate'
' more invoices please use the validate on background option', self.batch_size))
Expand Down

0 comments on commit aac4699

Please sign in to comment.