Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] account_post_in_background: add new module
- Loading branch information
Showing
8 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from . import wizards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
'name': 'Account Post In Background', | ||
'version': "16.0.1.0.0", | ||
'author': 'ADHOC SA', | ||
'depends': [ | ||
'account', | ||
], | ||
'data': [ | ||
'validate_account_move_views.xml', | ||
'data/ir_cron.xml', | ||
], | ||
'license': 'AGPL-3', | ||
'installable': True, | ||
'auto_install': False, | ||
'application': False, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record forcecreate="True" id="ir_cron_background_post_invoices" model="ir.cron"> | ||
<field name="name">Background Post Invoices: cron</field> | ||
<field name="model_id" ref="account.model_account_move"/> | ||
<field name="state">code</field> | ||
<field name="code">model._cron_background_post_invoices()</field> | ||
<field eval="True" name="active" /> | ||
<field name="interval_number">1</field> | ||
<field name="interval_type">hours</field> | ||
<field name="numbercall">-1</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import account_move |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from odoo import _, api, fields, models | ||
|
||
|
||
class AccountMove(models.Model): | ||
|
||
_inherit = 'account_move' | ||
|
||
background_validate = fields.Boolean(help="If True then this invoice will be validated in the background by cron.") | ||
|
||
@api.model | ||
def _cron_background_post_invoices(self): | ||
moves = self.search([('background_validate', '=', True)]) | ||
if moves: | ||
try: | ||
moves[0]._post() | ||
moves[0]._cr.commit() | ||
except Exception as exp: | ||
moves[0].background_validate = False | ||
moves[0].message_post(_('We tried to validate this invoice on the background but got this error: %s') % str(exp)) | ||
# TODO KZ revisar que solo se este enviando a followers internos del documento | ||
if len(moves) > 1: | ||
self.env.ref('account_post_in_background.ir_cron_background_post_invoices')._trigger() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import validate_account_move |
35 changes: 35 additions & 0 deletions
35
account_post_in_background/wizards/validate_account_move.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from odoo import api, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class ValidateAccountMove(models.TransientModel): | ||
|
||
_inherit = "validate.account.move" | ||
|
||
count_inv = fields.Integer(help="Technical field to know the number of invoices selected from the wizard") | ||
|
||
@api.model | ||
def default_get(self, fields): | ||
res = super().default_get(fields) | ||
|
||
if self._context.get('active_model') == 'account.move': | ||
domain = [('id', 'in', self._context.get('active_ids', [])), ('state', '=', 'draft')] | ||
elif self._context.get('active_model') == 'account.journal': | ||
domain = [('journal_id', '=', self._context.get('active_id')), ('state', '=', 'draft')] | ||
else: | ||
raise UserError(_("Missing 'active_model' in context.")) | ||
|
||
res['count_inv']: self.env['account.move'].search_count(domain) | ||
return res | ||
|
||
def action_background_validate(self): | ||
# TODO KZ esto no me gusta que se haga varias veces, con que lo calculemos una sola vez deberia de ir | ||
if self._context.get('active_model') == 'account.move': | ||
domain = [('id', 'in', self._context.get('active_ids', [])), ('state', '=', 'draft')] | ||
elif self._context.get('active_model') == 'account.journal': | ||
domain = [('journal_id', '=', self._context.get('active_id')), ('state', '=', 'draft')] | ||
else: | ||
raise UserError(_("Missing 'active_model' in context.")) | ||
|
||
self.env['account.move'].search(domain).background_validate = True | ||
|
30 changes: 30 additions & 0 deletions
30
account_post_in_background/wizards/validate_account_move_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<data> | ||
|
||
<record id="validate_account_move_view" model="ir.ui.view"> | ||
<field name="name">Post Journal Entries</field> | ||
<field name="model">validate.account.move</field> | ||
<field name="inherit_id" ref="account.validate_account_move_view"/> | ||
<field name="arch" type="xml"> | ||
|
||
<field name="force_post" position="after"> | ||
<field name="count_inv" invisible="1"/> | ||
</field> | ||
|
||
<button name="validate_move" position="before"> | ||
<button string="Post in Background" name="action_background_validate" type="object" default_focus="1" class="btn-primary" data-hotkey="a" help="With this, all the invoices selected to be validated will be marked and they will be validated one by one. If an error is found when validating any invoice, the automatic validation of the same will be unmarked and it will be notified via messaging.") | ||
/> | ||
</button> | ||
|
||
<button name="validate_move" position="attributes"> | ||
<attribute name="default_focus"/> | ||
<attribute name="class"/> | ||
<attribute name="attrs">{'invisible': [('count_inv', '>=', 20)]}</attribute> | ||
</button> | ||
|
||
</field> | ||
</record> | ||
|
||
</data> | ||
</odoo> |