Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] account_background_post: Add validation to bypass the validate_move method when running a test and run the original method of odoo #187

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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