~camptocamp/banking-addons/bank-statement-reconcile-70-pending-merge

« back to all changes in this revision

Viewing changes to account_advanced_reconcile_bank_statement/advanced_reconciliation.py

  • Committer: Matthieu Dietrich
  • Date: 2014-05-27 14:14:23 UTC
  • Revision ID: matthieu.dietrich@camptocamp.com-20140527141423-nfetynjpkfm2ye4i
[ADD] new reconciliation rule using bank statements

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Author: Matthieu Dietrich. Copyright Camptocamp SA
 
5
#
 
6
#    This program is free software: you can redistribute it and/or modify
 
7
#    it under the terms of the GNU Affero General Public License as
 
8
#    published by the Free Software Foundation, either version 3 of the
 
9
#    License, or (at your option) any later version.
 
10
#
 
11
#    This program is distributed in the hope that it will be useful,
 
12
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#    GNU Affero General Public License for more details.
 
15
#
 
16
#    You should have received a copy of the GNU Affero General Public License
 
17
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
#
 
19
##############################################################################
 
20
 
 
21
from openerp.osv import orm
 
22
 
 
23
 
 
24
class easy_reconcile_advanced_bank_statement(orm.TransientModel):
 
25
 
 
26
    _name = 'easy.reconcile.advanced.bank_statement'
 
27
    _inherit = 'easy.reconcile.advanced'
 
28
 
 
29
    def _skip_line(self, cr, uid, rec, move_line, context=None):
 
30
        """
 
31
        When True is returned on some conditions, the credit move line
 
32
        will be skipped for reconciliation. Can be inherited to
 
33
        skip on some conditions. ie: ref or partner_id is empty.
 
34
        """
 
35
        return not (move_line.get('ref') and
 
36
                    move_line.get('partner_id'))
 
37
 
 
38
    def _matchers(self, cr, uid, rec, move_line, context=None):
 
39
        return (('partner_id', move_line['partner_id']),
 
40
                ('ref', move_line['ref'].lower().strip()))
 
41
 
 
42
    def _opposite_matchers(self, cr, uid, rec, move_line, context=None):
 
43
        yield ('partner_id', move_line['partner_id'])
 
44
        if move_line['statement_id']:
 
45
            cr.execute("""SELECT name FROM account_bank_statement
 
46
                          WHERE id = %s""", (move_line['statement_id'],))
 
47
            statement_name = cr.fetchone()[0]
 
48
            yield ('ref', statement_name.lower().strip())
 
49
        else:
 
50
            yield ('ref', '')
 
51
 
 
52
    # Re-defined for this particular rule; since the commission line is a
 
53
    # credit line inside of the target statement, it should also be considered
 
54
    # as an opposite to be reconciled.
 
55
    def _action_rec(self, cr, uid, rec, context=None):
 
56
        credit_lines = self._query_credit(cr, uid, rec, context=context)
 
57
        debit_lines = self._query_debit(cr, uid, rec, context=context)
 
58
        return self._rec_auto_lines_advanced(
 
59
                cr, uid, rec, credit_lines, credit_lines + debit_lines,
 
60
                context=context)