mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
allow to configure reconcile_commit_every
this allows to configure if we want to commit the automatic reconcile every N lines. It is left to zero by default to avoid possible problems with tests that rely on a transaction.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Guewen Baconnier
|
||||
# Copyright 2012 Camptocamp SA
|
||||
# Author: Guewen Baconnier, Leonardo Pistone
|
||||
# Copyright 2012-2014 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -22,3 +22,4 @@
|
||||
import easy_reconcile
|
||||
import base_advanced_reconciliation
|
||||
import advanced_reconciliation
|
||||
import res_config # noqa
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Guewen Baconnier
|
||||
# Copyright 2012 Camptocamp SA
|
||||
# Author: Guewen Baconnier, Leonardo Pistone
|
||||
# Copyright 2012-2014 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -73,7 +73,8 @@ many offices.
|
||||
|
||||
""",
|
||||
'website': 'http://www.camptocamp.com',
|
||||
'data': ['easy_reconcile_view.xml'],
|
||||
'data': ['easy_reconcile_view.xml',
|
||||
'res_config_view.xml'],
|
||||
'test': [],
|
||||
'images': [],
|
||||
'installable': True,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Guewen Baconnier
|
||||
# Copyright 2012 Camptocamp SA
|
||||
# Author: Guewen Baconnier, Leonardo Pistone
|
||||
# Copyright 2012-2014 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -23,8 +23,6 @@ from itertools import product
|
||||
from openerp.osv import orm
|
||||
from openerp import pooler
|
||||
|
||||
COMMIT_EVERY = 10
|
||||
|
||||
|
||||
class easy_reconcile_advanced(orm.AbstractModel):
|
||||
|
||||
@@ -228,14 +226,25 @@ class easy_reconcile_advanced(orm.AbstractModel):
|
||||
# often. We have to create it here and not later to avoid problems
|
||||
# where the new cursor sees the lines as reconciles but the old one
|
||||
# does not.
|
||||
new_cr = pooler.get_db(cr.dbname).cursor()
|
||||
if context is None:
|
||||
context = {}
|
||||
ctx = context.copy()
|
||||
ctx['commit_every'] = (
|
||||
rec.journal_id.company_id.reconciliation_commit_every
|
||||
)
|
||||
|
||||
if ctx['commit_every']:
|
||||
new_cr = pooler.get_db(cr.dbname).cursor()
|
||||
else:
|
||||
new_cr = cr
|
||||
try:
|
||||
credit_lines = self._query_credit(new_cr, uid, rec, context=context)
|
||||
debit_lines = self._query_debit(new_cr, uid, rec, context=context)
|
||||
credit_lines = self._query_credit(new_cr, uid, rec, context=ctx)
|
||||
debit_lines = self._query_debit(new_cr, uid, rec, context=ctx)
|
||||
result = self._rec_auto_lines_advanced(
|
||||
new_cr, uid, rec, credit_lines, debit_lines, context=context)
|
||||
new_cr, uid, rec, credit_lines, debit_lines, context=ctx)
|
||||
finally:
|
||||
new_cr.close()
|
||||
if ctx['commit_every']:
|
||||
new_cr.close()
|
||||
return result
|
||||
|
||||
def _skip_line(self, cr, uid, rec, move_line, context=None):
|
||||
@@ -282,7 +291,10 @@ class easy_reconcile_advanced(orm.AbstractModel):
|
||||
elif reconciled:
|
||||
partial_reconciled_ids += reconcile_group_ids
|
||||
|
||||
if COMMIT_EVERY and (group_count + 1) % COMMIT_EVERY == 0:
|
||||
if (
|
||||
context['commit_every']
|
||||
and (group_count + 1) % context['commit_every'] == 0
|
||||
):
|
||||
cr.commit()
|
||||
|
||||
return reconciled_ids, partial_reconciled_ids
|
||||
|
||||
59
account_advanced_reconcile/res_config.py
Normal file
59
account_advanced_reconcile/res_config.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Leonardo Pistone
|
||||
# Copyright 2014 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import orm, fields
|
||||
|
||||
|
||||
class AccountConfigSettings(orm.TransientModel):
|
||||
_inherit = 'account.config.settings'
|
||||
|
||||
_columns = {
|
||||
'reconciliation_commit_every': fields.related(
|
||||
'company_id',
|
||||
'reconciliation_commit_every',
|
||||
type='integer',
|
||||
string='How often to commit when performing automatic '
|
||||
'reconciliation.',
|
||||
help="""Leave zero to commit only at the end of the process."""),
|
||||
}
|
||||
|
||||
def onchange_company_id(self, cr, uid, ids, company_id, context=None):
|
||||
company_obj = self.pool['res.company']
|
||||
|
||||
result = super(AccountConfigSettings, self).onchange_company_id(
|
||||
cr, uid, ids, company_id, context=None)
|
||||
|
||||
if company_id:
|
||||
company = company_obj.browse(cr, uid, company_id, context=context)
|
||||
result['value']['reconciliation_commit_every'] = (
|
||||
company.reconciliation_commit_every
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
class Company(orm.Model):
|
||||
_inherit = "res.company"
|
||||
_columns = {
|
||||
'reconciliation_commit_every': fields.integer(
|
||||
string='How often to commit when performing automatic '
|
||||
'reconciliation.',
|
||||
help="""Leave zero to commit only at the end of the process."""),
|
||||
}
|
||||
24
account_advanced_reconcile/res_config_view.xml
Normal file
24
account_advanced_reconcile/res_config_view.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_account_config" model="ir.ui.view">
|
||||
<field name="name">account settings</field>
|
||||
<field name="model">account.config.settings</field>
|
||||
<field name="inherit_id" ref="account.view_account_config_settings"/>
|
||||
<field name="arch" type="xml">
|
||||
<separator string="eInvoicing & Payments" position="before">
|
||||
<separator string="Reconciliation"/>
|
||||
<group>
|
||||
<label for="id" string="Options"/>
|
||||
<div name="reconciliation_config">
|
||||
<div>
|
||||
<label for="reconciliation_commit_every"/>
|
||||
<field name="reconciliation_commit_every" class="oe_inline"/>
|
||||
</div>
|
||||
</div>
|
||||
</group>
|
||||
</separator>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user