mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[IMP] decouple the methods configuration and the reconciliations TransientModels, allowing to runs the automatic reconciliations without any configuration (from an other wizard, a bank statement or whatever)
(lp:account-extra-addons rev 26.1.16)
This commit is contained in:
@@ -29,9 +29,14 @@ class easy_reconcile_base(AbstractModel):
|
||||
|
||||
_name = 'easy.reconcile.base'
|
||||
|
||||
_inherit = 'easy.reconcile.options'
|
||||
_auto = True # restore property set to False by AbstractModel
|
||||
|
||||
_columns = {
|
||||
'easy_reconcile_id': fields.many2one('account.easy.reconcile',
|
||||
string='Easy Reconcile')
|
||||
'account_id': fields.many2one('account.account', 'Account', required=True),
|
||||
'partner_ids': fields.many2many('res.partner',
|
||||
string="Restrict on partners"),
|
||||
# other columns are inherited from easy.reconcile.options
|
||||
}
|
||||
|
||||
def automatic_reconcile(self, cr, uid, ids, context=None):
|
||||
@@ -80,16 +85,20 @@ class easy_reconcile_base(AbstractModel):
|
||||
# but as we use _where_calc in _get_filter
|
||||
# which returns a list, we have to
|
||||
# accomodate with that
|
||||
params = [rec.easy_reconcile_id.account.id]
|
||||
params = [rec.account_id.id]
|
||||
|
||||
if rec.partner_ids:
|
||||
where += " AND account_move_line.partner_id IN %s"
|
||||
params.append(tuple([l.id for l in rec.partner_ids]))
|
||||
return where, params
|
||||
|
||||
def _get_filter(self, cr, uid, rec, context):
|
||||
ml_obj = self.pool.get('account.move.line')
|
||||
where = ''
|
||||
params = []
|
||||
if context.get('filter'):
|
||||
if rec.filter:
|
||||
dummy, where, params = ml_obj._where_calc(
|
||||
cr, uid, context['filter'], context=context).get_sql()
|
||||
cr, uid, rec.filter, context=context).get_sql()
|
||||
if where:
|
||||
where = " AND %s" % where
|
||||
return where, params
|
||||
@@ -157,7 +166,7 @@ class easy_reconcile_base(AbstractModel):
|
||||
context = {}
|
||||
|
||||
ml_obj = self.pool.get('account.move.line')
|
||||
writeoff = context.get('write_off', 0.)
|
||||
writeoff = rec.write_off
|
||||
|
||||
keys = ('debit', 'credit')
|
||||
|
||||
@@ -165,14 +174,15 @@ class easy_reconcile_base(AbstractModel):
|
||||
below_writeoff, sum_debit, sum_credit = self._below_writeoff_limit(
|
||||
cr, uid, rec, lines, writeoff, context=context)
|
||||
date = self._get_rec_date(
|
||||
cr, uid, rec, lines, context.get('date_base_on'), context=context)
|
||||
cr, uid, rec, lines, rec.date_base_on, context=context)
|
||||
|
||||
import pdb; pdb.set_trace()
|
||||
rec_ctx = dict(context, date_p=date)
|
||||
if below_writeoff:
|
||||
if sum_credit < sum_debit:
|
||||
writeoff_account_id = context.get('account_profit_id', False)
|
||||
writeoff_account_id = rec.account_profit_id.id
|
||||
else:
|
||||
writeoff_account_id = context.get('account_lost_id', False)
|
||||
writeoff_account_id = rec.account_lost_id.id
|
||||
|
||||
period_id = self.pool.get('account.period').find(
|
||||
cr, uid, dt=date, context=context)[0]
|
||||
@@ -183,7 +193,7 @@ class easy_reconcile_base(AbstractModel):
|
||||
type='auto',
|
||||
writeoff_acc_id=writeoff_account_id,
|
||||
writeoff_period_id=period_id,
|
||||
writeoff_journal_id=context.get('journal_id'),
|
||||
writeoff_journal_id=rec.journal_id.id,
|
||||
context=rec_ctx)
|
||||
return True, True
|
||||
elif allow_partial:
|
||||
|
||||
@@ -20,25 +20,21 @@
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv.orm import Model, AbstractModel
|
||||
from openerp.osv import fields
|
||||
from openerp.tools.translate import _
|
||||
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
|
||||
|
||||
class account_easy_reconcile_method(Model):
|
||||
class easy_reconcile_options(AbstractModel):
|
||||
"""Options of a reconciliation profile, columns
|
||||
shared by the configuration of methods and by the
|
||||
reconciliation wizards. This allows decoupling
|
||||
of the methods with the wizards and allows to
|
||||
launch the wizards alone
|
||||
"""
|
||||
|
||||
_name = 'account.easy.reconcile.method'
|
||||
_description = 'reconcile method for account_easy_reconcile'
|
||||
|
||||
def _get_all_rec_method(self, cr, uid, context=None):
|
||||
return [
|
||||
('easy.reconcile.simple.name', 'Simple method based on amount and name'),
|
||||
('easy.reconcile.simple.partner', 'Simple method based on amount and partner'),
|
||||
]
|
||||
|
||||
def _get_rec_method(self, cr, uid, context=None):
|
||||
return self._get_all_rec_method(cr, uid, context=None)
|
||||
_name = 'easy.reconcile.options'
|
||||
|
||||
def _get_rec_base_date(self, cr, uid, context=None):
|
||||
return [('end_period_last_credit', 'End of period of most recent credit'),
|
||||
@@ -49,9 +45,7 @@ class account_easy_reconcile_method(Model):
|
||||
('newest_debit', 'Date of most recent debit')]
|
||||
|
||||
_columns = {
|
||||
'name': fields.selection(_get_rec_method, 'Type', size=128, required=True),
|
||||
'sequence': fields.integer('Sequence', required=True, help="The sequence field is used to order the reconcile method"),
|
||||
'write_off': fields.float('Write off Value'),
|
||||
'write_off': fields.float('Write off allowed'),
|
||||
'account_lost_id': fields.many2one('account.account', 'Account Lost'),
|
||||
'account_profit_id': fields.many2one('account.account', 'Account Profit'),
|
||||
'journal_id': fields.many2one('account.journal', 'Journal'),
|
||||
@@ -59,17 +53,45 @@ class account_easy_reconcile_method(Model):
|
||||
required=True,
|
||||
string='Date of reconcilation'),
|
||||
'filter': fields.char('Filter', size=128),
|
||||
'task_id': fields.many2one('account.easy.reconcile', 'Task', required=True, ondelete='cascade'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'write_off': 0,
|
||||
'sequence': 0,
|
||||
'write_off': 0.,
|
||||
'date_base_on': 'end_period_last_credit',
|
||||
}
|
||||
|
||||
|
||||
class account_easy_reconcile_method(Model):
|
||||
|
||||
_name = 'account.easy.reconcile.method'
|
||||
_description = 'reconcile method for account_easy_reconcile'
|
||||
|
||||
_inherit = 'easy.reconcile.options'
|
||||
_auto = True # restore property set to False by AbstractModel
|
||||
|
||||
_order = 'sequence'
|
||||
|
||||
def _get_all_rec_method(self, cr, uid, context=None):
|
||||
return [
|
||||
('easy.reconcile.simple.name', 'Simple method based on amount and name'),
|
||||
('easy.reconcile.simple.partner', 'Simple method based on amount and partner'),
|
||||
]
|
||||
|
||||
def _get_rec_method(self, cr, uid, context=None):
|
||||
return self._get_all_rec_method(cr, uid, context=None)
|
||||
|
||||
_columns = {
|
||||
'name': fields.selection(_get_rec_method, 'Type', size=128, required=True),
|
||||
'sequence': fields.integer('Sequence', required=True,
|
||||
help="The sequence field is used to order the reconcile method"),
|
||||
'task_id': fields.many2one('account.easy.reconcile', 'Task',
|
||||
required=True, ondelete='cascade'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'sequence': 1,
|
||||
}
|
||||
|
||||
def init(self, cr):
|
||||
""" Migration stuff, name is not anymore methods names
|
||||
but models name"""
|
||||
@@ -126,6 +148,17 @@ class account_easy_reconcile(Model):
|
||||
type='integer', string='Partially Reconciled Entries'),
|
||||
}
|
||||
|
||||
def _prepare_run_transient(self, cr, uid, rec_method, context=None):
|
||||
return {'account_id': rec_method.task_id.account.id,
|
||||
'write_off': rec_method.write_off,
|
||||
'account_lost_id': rec_method.account_lost_id and \
|
||||
rec_method.account_lost_id.id,
|
||||
'account_profit_id': rec_method.account_profit_id and \
|
||||
rec_method.account_profit_id.id,
|
||||
'journal_id': rec_method.journal_id and rec_method.journal_id.id,
|
||||
'date_base_on': rec_method.date_base_on,
|
||||
'filter': rec_method.filter}
|
||||
|
||||
def run_reconcile(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
@@ -138,20 +171,15 @@ class account_easy_reconcile(Model):
|
||||
|
||||
for method in rec.reconcile_method:
|
||||
count += 1
|
||||
ctx = dict(
|
||||
context,
|
||||
date_base_on=method.date_base_on,
|
||||
filter=eval(method.filter or '[]'),
|
||||
write_off=(method.write_off > 0 and method.write_off) or 0,
|
||||
account_lost_id=method.account_lost_id.id,
|
||||
account_profit_id=method.account_profit_id.id,
|
||||
journal_id=method.journal_id.id)
|
||||
|
||||
rec_model = self.pool.get(method.name)
|
||||
auto_rec_id = rec_model.create(
|
||||
cr, uid, {'easy_reconcile_id': rec_id}, context=ctx)
|
||||
cr, uid,
|
||||
self._prepare_run_transient(cr, uid, method, context=context),
|
||||
context=context)
|
||||
|
||||
rec_ids, partial_ids = rec_model.automatic_reconcile(
|
||||
cr, uid, auto_rec_id, context=ctx)
|
||||
cr, uid, auto_rec_id, context=context)
|
||||
|
||||
details.append(_('method %d : full: %d lines, partial: %d lines') % \
|
||||
(count, len(rec_ids), len(partial_ids)))
|
||||
|
||||
Reference in New Issue
Block a user