Skip to content

Commit

Permalink
[ADD] account_background_post: action_post
Browse files Browse the repository at this point in the history
Use action_post instead of post because action_post do things we
need that the _post dont: like some validations, send emails and
another payments extra steps.

In this case we hive the force_post boolean because is confusing,
now it does not do anything, all the invoices will be validated
without taking into account the accounting date
  • Loading branch information
zaoral committed Sep 28, 2023
1 parent a373b8c commit 37cfdfd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion account_background_post/models/account_move.py
Expand Up @@ -27,7 +27,7 @@ def _cron_background_post_invoices(self, batch_size=20):

for move in moves[:batch_size]:
try:
move._post()
move.action_post()
move.background_post = False
move._cr.commit()
except Exception as exp:
Expand Down
8 changes: 5 additions & 3 deletions account_background_post/wizards/validate_account_move.py
Expand Up @@ -47,10 +47,12 @@ def action_background_post(self):
def validate_move(self):
""" Sobre escribimos este metodo por completo para hacer:
1. que se valida cada factura una a uno y no todas jutnas. esto para evitar problemas que puedan surgier
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.
2. que se valida cada factura una a uno y no todas jutnas. esto para evitar problemas que puedan surgier
por errores, que no se puedan ejecutar los commits que tenemos para guardar el estado de factura electronica y tambien para asegurar que tras cada fatura se envie su email, asi si hay un error posterior las facturas que fueron validadas aseguremos que hayan sido totalmente procesadas.
2. Limitamos sui el usuario quiere validar mas facturas que el batch size definido directamente
3. Limitamos sui el usuario quiere validar mas facturas que el batch size definido directamente
le pedimos que las valide en background. """

if self.count_inv > self.batch_size:
Expand All @@ -59,7 +61,7 @@ def validate_move(self):

for move in self.move_ids:
_logger.info('Validating invoice %s', move.id)
move._post(not self.force_post)
move.action_post()
move._cr.commit()

return {'type': 'ir.actions.act_window_close'}
Expand Up @@ -8,6 +8,10 @@
<field name="inherit_id" ref="account.validate_account_move_view"/>
<field name="arch" type="xml">

<field name="force_post" position="attributes">
<attribute name="invisible">1</attribute>
</field>

<field name="force_post" position="after">
<field name="count_inv" invisible="1"/>
<field name="force_background" invisible="1"/>
Expand Down

0 comments on commit 37cfdfd

Please sign in to comment.