Skip to content

Commit bd9991a

Browse files
committed
[FIX] account_background_post: validate with super when is only 1 invoice
closes #210 Related: ingadhoc/account-financial-tools#696 Signed-off-by: rov-adhoc <rov@adhoc.com.ar>
1 parent 3bf1f5c commit bd9991a

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

account_background_post/wizards/validate_account_move.py

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
from odoo import _, api, fields, models
3+
from odoo import _, fields, models
44
from odoo.exceptions import UserError
55

66
_logger = logging.getLogger(__name__)
@@ -21,31 +21,18 @@ def _compute_force_background(self):
2121
for rec in self:
2222
rec.force_background = rec.count_inv > rec.batch_size
2323

24-
@api.model
2524
def default_get(self, fields):
2625
res = super().default_get(fields)
27-
28-
if self._context.get("active_model") == "account.move":
29-
domain = [("id", "in", self._context.get("active_ids", [])), ("state", "=", "draft")]
30-
elif self._context.get("active_model") == "account.journal":
31-
domain = [("journal_id", "=", self._context.get("active_id")), ("state", "=", "draft")]
32-
else:
33-
raise UserError(_("Missing 'active_model' in context."))
34-
35-
moves = self.env["account.move"].search(domain).filtered("line_ids")
36-
if not moves:
37-
raise UserError(_("There are no journal items in the draft state to post."))
38-
39-
res["move_ids"] = moves.ids
40-
res["count_inv"] = len(moves)
26+
if res:
27+
res["count_inv"] = len(res["move_ids"])
4128
return res
4229

4330
def action_background_post(self):
4431
self.move_ids.background_post = True
4532
self.env.ref("account_background_post.ir_cron_background_post_invoices")._trigger()
4633

4734
def validate_move(self):
48-
"""Sobre escribimos este metodo por completo para hacer:
35+
"""Sobre escribimos este método para el caso de varias invoices para hacer:
4936
5037
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.
5138
@@ -55,6 +42,9 @@ def validate_move(self):
5542
3. Limitamos sui el usuario quiere validar mas facturas que el batch size definido directamente
5643
le pedimos que las valide en background."""
5744

45+
if len(self) == 1:
46+
return super().validate_move()
47+
5848
if self.count_inv > self.batch_size:
5949
raise UserError(
6050
_(

0 commit comments

Comments
 (0)