Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8.0 pep8 v7 forward port #33

Closed
wants to merge 56 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
0ca4175
In account_easy_reconcile, now write-off entries can be created with …
guewen Mar 27, 2014
c45e47d
Improvement on the account_statement_base_import module to have profi…
pedrobaeza Jul 2, 2014
beea3e1
Create README.md
pedrobaeza Jul 2, 2014
59234d8
Merge pull request #9 from lepistone/7.0-account_easy_reconcile-analy…
lepistone Jul 11, 2014
56f6818
Merge pull request #4 from pedrobaeza/7.0-bank-statement-reconcile-pr…
pedrobaeza Jul 14, 2014
2971f66
[imp] auto reconcile: commit every 10 lines
lepistone Jul 15, 2014
8193d5d
refactor as suggested by @guewen
lepistone Jul 15, 2014
7b735ac
Merge pull request #12 from lepistone/easy_reconcile_commit
bwrsandman Jul 16, 2014
8f5861e
Add meta files
bwrsandman Jul 16, 2014
e5cfdfc
Add account-financial-tools dependency
bwrsandman Jul 16, 2014
3bf9710
allow to configure reconcile_commit_every
lepistone Jul 16, 2014
5c0f812
easy auto reconcile: commit at the end
lepistone Jul 16, 2014
996dea7
I'm a contributor, not an author
lepistone Jul 16, 2014
a1245da
Add ofxparse python dependency
bwrsandman Jul 16, 2014
1d1ae57
Merge pull request #15 from lepistone/easy_reconcile_commit_settings
lepistone Jul 16, 2014
1a96b22
Add logging during reconcile
guewen Jul 18, 2014
f40fe31
Wrong count of credit lines
guewen Jul 18, 2014
c6e8ea5
[FIX] API Improvement
florian-dacosta Jul 23, 2014
30525cf
fix docstring
florian-dacosta Jul 23, 2014
a61698b
fix docstring
florian-dacosta Jul 23, 2014
f6c5967
Merge pull request #19 from guewen/advanced-reconcile-logging
yvaucher Jul 28, 2014
d081f6c
Merge pull request #13 from bwrsandman/7.0-metafiles
yvaucher Jul 31, 2014
c1cf75d
[FIX] travis: update travis file to match the one in https://github.c…
lmignon Aug 1, 2014
bf46411
[FIX] travis: exclude account_statement_ext_point_of_sale (addon with…
lmignon Aug 1, 2014
18eb190
Merge pull request #25 from acsone/7.0-fix-travis
pedrobaeza Aug 1, 2014
7022628
[IMP] account_statement_base_import: Fill balance start when parser d…
pedrobaeza Aug 4, 2014
69c0e16
[FIX] Correct call order
pedrobaeza Aug 4, 2014
8e20a45
Merge pull request #22 from florian-dacosta/api_improvement
pedrobaeza Aug 4, 2014
2c1773e
Merge pull request #27 from pedrobaeza/7.0-import_start_balance_null
pedrobaeza Aug 4, 2014
44a59ce
autopep8
pedrobaeza Aug 4, 2014
2ec18f7
[IMP] account_statement_transactionid_import: Fix PEP8
pedrobaeza Aug 4, 2014
4a1c950
[IMP] account_easy_reconcile: Fix PEP8
pedrobaeza Aug 4, 2014
5072c71
[IMP] statement_voucher_killer: Fix PEP8
pedrobaeza Aug 4, 2014
f1e0b78
[IMP] account_advanced_reconcile: Fix PEP8
pedrobaeza Aug 4, 2014
c6298b0
[IMP] account_statement_base_completion: Fix PEP8
pedrobaeza Aug 4, 2014
b3c1aa9
[IMP] account_statement_so_completion: Fix PEP8
pedrobaeza Aug 4, 2014
5e98a81
[IMP] account_statement_ext_voucher: Fix PEP8
pedrobaeza Aug 4, 2014
d0a06fd
[IMP] account_statement_one_move: Fix PEP8
pedrobaeza Aug 4, 2014
66af054
[IMP] account_statement_ext_point_of_sale: Fix PEP8
pedrobaeza Aug 4, 2014
d64122c
[IMP] account_statement_regex_account_completion: Fix PEP8
pedrobaeza Aug 4, 2014
602d39d
[IMP] account_statement_completion_label: Fix PEP8
pedrobaeza Aug 4, 2014
aebcbfd
[IMP] account_invoice_reference: Fix PEP8
pedrobaeza Aug 4, 2014
d9a943d
[IMP] account_statement_base_import: Fix PEP8
pedrobaeza Aug 4, 2014
a851336
[IMP] account_statement_transactionid_completion: Fix PEP8
pedrobaeza Aug 4, 2014
6ccd6f4
[IMP] account_statement_commission: Fix PEP8
pedrobaeza Aug 4, 2014
9facd19
[IMP] account_statement_no_invoice_import: Fix PEP8
pedrobaeza Aug 4, 2014
5f0628b
[IMP] account_statement_ofx_import: Fix PEP8
pedrobaeza Aug 4, 2014
48e03e6
[IMP] account_advanced_reconcile_transaction_ref: Fix PEP8
pedrobaeza Aug 4, 2014
5cfa975
[IMP] account_statement_completion_voucher: Fix PEP8
pedrobaeza Aug 4, 2014
85d139f
[IMP] account_statement_completion_voucher: Fix PEP8
pedrobaeza Aug 4, 2014
b94bebe
[IMP] account_statement_bankaccount_completion: Fix PEP8
pedrobaeza Aug 4, 2014
b522f28
Fix Travis errors
pedrobaeza Aug 4, 2014
4e13e0e
F401 remaining
pedrobaeza Aug 4, 2014
a33cfa6
Fix multiline docstring param
pedrobaeza Aug 5, 2014
c0cbab8
Merge pull request #31 from pedrobaeza/7.0-pep8_fix
pedrobaeza Aug 6, 2014
8496d84
Merge remote-tracking branch 'upstream/7.0' into 8.0-port-base-import
lmignon Aug 6, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion __unported__/account_advanced_reconcile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
##############################################################################
#
# Author: Guewen Baconnier
# Copyright 2012 Camptocamp SA
# Contributor: 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
Expand All @@ -22,3 +23,4 @@
import easy_reconcile
import base_advanced_reconciliation
import advanced_reconciliation
import res_config # noqa
14 changes: 8 additions & 6 deletions __unported__/account_advanced_reconcile/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
##############################################################################
#
# Author: Guewen Baconnier
# Copyright 2012 Camptocamp SA
# Contributor: 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
Expand Down Expand Up @@ -63,21 +64,22 @@
possible.

So basically, if you have an invoice with 3 payments (one per month), the first
month, it will partial reconcile the debit move line with the first payment, the second
month, it will partial reconcile the debit move line with 2 first payments,
the third month, it will make the full reconciliation.
month, it will partial reconcile the debit move line with the first payment, the
second month, it will partial reconcile the debit move line with 2 first
payments, the third month, it will make the full reconciliation.

This module is perfectly adapted for E-Commerce business where a big volume of
move lines and so, reconciliations, are involved and payments often come from
many offices.

""",
'website': 'http://www.camptocamp.com',
'data': ['easy_reconcile_view.xml'],
'data': ['easy_reconcile_view.xml',
'res_config_view.xml'],
'test': [],
'images': [],
'installable': False,
'auto_install': False,
'license': 'AGPL-3',
'application': True,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
##############################################################################
#
# Author: Guewen Baconnier
# Copyright 2012 Camptocamp SA
# Contributor: 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
Expand All @@ -18,13 +19,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging

from itertools import product
from openerp.osv import orm
from openerp import pooler
from openerp.tools.translate import _


class easy_reconcile_advanced(orm.AbstractModel):
_logger = logging.getLogger(__name__)


class easy_reconcile_advanced(orm.AbstractModel):
_name = 'easy.reconcile.advanced'
_inherit = 'easy.reconcile.base'

Expand All @@ -34,11 +40,8 @@ def _query_debit(self, cr, uid, rec, context=None):
sql_from = self._from(rec)
where, params = self._where(rec)
where += " AND account_move_line.debit > 0 "

where2, params2 = self._get_filter(cr, uid, rec, context=context)

query = ' '.join((select, sql_from, where, where2))

cr.execute(query, params + params2)
return cr.dictfetchall()

Expand All @@ -48,11 +51,8 @@ def _query_credit(self, cr, uid, rec, context=None):
sql_from = self._from(rec)
where, params = self._where(rec)
where += " AND account_move_line.credit > 0 "

where2, params2 = self._get_filter(cr, uid, rec, context=context)

query = ' '.join((select, sql_from, where, where2))

cr.execute(query, params + params2)
return cr.dictfetchall()

Expand Down Expand Up @@ -170,14 +170,15 @@ def _compare_matchers(matcher, opposite_matcher):
"""
mkey, mvalue = matcher
omkey, omvalue = opposite_matcher
assert mkey == omkey, ("A matcher %s is compared with a matcher %s, "
" the _matchers and _opposite_matchers are probably wrong" %
(mkey, omkey))
assert mkey == omkey, \
(_("A matcher %s is compared with a matcher %s, the _matchers and "
"_opposite_matchers are probably wrong") % (mkey, omkey))
if not isinstance(mvalue, (list, tuple)):
mvalue = mvalue,
if not isinstance(omvalue, (list, tuple)):
omvalue = omvalue,
return easy_reconcile_advanced._compare_matcher_values(mkey, mvalue, omvalue)
return easy_reconcile_advanced._compare_matcher_values(mkey, mvalue,
omvalue)

def _compare_opposite(self, cr, uid, rec, move_line, opposite_move_line,
matchers, context=None):
Expand All @@ -188,7 +189,7 @@ def _compare_opposite(self, cr, uid, rec, move_line, opposite_move_line,
they are candidate for a reconciliation.
"""
opp_matchers = self._opposite_matchers(cr, uid, rec, opposite_move_line,
context=context)
context=context)
for matcher in matchers:
try:
opp_matcher = opp_matchers.next()
Expand All @@ -206,13 +207,13 @@ def _compare_opposite(self, cr, uid, rec, move_line, opposite_move_line,

return True

def _search_opposites(self, cr, uid, rec, move_line, opposite_move_lines, context=None):
"""
Search the opposite move lines for a move line
def _search_opposites(self, cr, uid, rec, move_line, opposite_move_lines,
context=None):
"""Search the opposite move lines for a move line

:param dict move_line: the move line for which we search opposites
:param list opposite_move_lines: list of dict of move lines values, the move
lines we want to search for
:param list opposite_move_lines: list of dict of move lines values,
the move lines we want to search for
:return: list of matching lines
"""
matchers = self._matchers(cr, uid, rec, move_line, context=context)
Expand All @@ -221,10 +222,30 @@ def _search_opposites(self, cr, uid, rec, move_line, opposite_move_lines, contex
cr, uid, rec, move_line, op, matchers, context=context)]

def _action_rec(self, cr, uid, rec, context=None):
credit_lines = self._query_credit(cr, uid, rec, context=context)
debit_lines = self._query_debit(cr, uid, rec, context=context)
return self._rec_auto_lines_advanced(
cr, uid, rec, credit_lines, debit_lines, context=context)
# we use a new cursor to be able to commit the reconciliation
# 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.
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=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=ctx)
finally:
if ctx['commit_every']:
new_cr.commit()
new_cr.close()
return result

def _skip_line(self, cr, uid, rec, move_line, context=None):
"""
Expand All @@ -234,33 +255,41 @@ def _skip_line(self, cr, uid, rec, move_line, context=None):
"""
return False

def _rec_auto_lines_advanced(self, cr, uid, rec, credit_lines, debit_lines, context=None):
def _rec_auto_lines_advanced(self, cr, uid, rec, credit_lines, debit_lines,
context=None):
""" Advanced reconciliation main loop """
reconciled_ids = []
partial_reconciled_ids = []
reconcile_groups = []

for credit_line in credit_lines:
_logger.info("%d credit lines to reconcile", len(credit_lines))
for idx, credit_line in enumerate(credit_lines, start=1):
if idx % 50 == 0:
_logger.info("... %d/%d credit lines inspected ...", idx,
len(credit_lines))
if self._skip_line(cr, uid, rec, credit_line, context=context):
continue

opposite_lines = self._search_opposites(
cr, uid, rec, credit_line, debit_lines, context=context)

if not opposite_lines:
continue

opposite_ids = [l['id'] for l in opposite_lines]
line_ids = opposite_ids + [credit_line['id']]
for group in reconcile_groups:
if any([lid in group for lid in opposite_ids]):
_logger.debug("New lines %s matched with an existing "
"group %s", line_ids, group)
group.update(line_ids)
break
else:
_logger.debug("New group of lines matched %s", line_ids)
reconcile_groups.append(set(line_ids))

lines_by_id = dict([(l['id'], l) for l in credit_lines + debit_lines])
for reconcile_group_ids in reconcile_groups:
_logger.info("Found %d groups to reconcile", len(reconcile_groups))
for group_count, reconcile_group_ids in enumerate(reconcile_groups,
start=1):
_logger.debug("Reconciling group %d/%d with ids %s",
group_count, len(reconcile_groups),
reconcile_group_ids)
group_lines = [lines_by_id[lid] for lid in reconcile_group_ids]
reconciled, full = self._reconcile_lines(
cr, uid, rec, group_lines, allow_partial=True, context=context)
Expand All @@ -269,4 +298,10 @@ def _rec_auto_lines_advanced(self, cr, uid, rec, credit_lines, debit_lines, cont
elif reconciled:
partial_reconciled_ids += reconcile_group_ids

if (context['commit_every'] and
group_count % context['commit_every'] == 0):
cr.commit()
_logger.info("Commit the reconciliations after %d groups",
group_count)
_logger.info("Reconciliation is over")
return reconciled_ids, partial_reconciled_ids
59 changes: 59 additions & 0 deletions __unported__/account_advanced_reconcile/res_config.py
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions __unported__/account_advanced_reconcile/res_config_view.xml
Original file line number Diff line number Diff line change
@@ -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 &amp; 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>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################

{'name': 'Advanced Reconcile Transaction Ref',
'description': """
'description': """
Advanced reconciliation method for the module account_advanced_reconcile
========================================================================
Reconcile rules with transaction_ref
Expand All @@ -32,9 +32,8 @@
'depends': ['account_advanced_reconcile'],
'data': ['easy_reconcile_view.xml'],
'demo': [],
'test': [], # To be ported or migrate to unit tests or scenarios
'test': [], # To be ported or migrate to unit tests or scenarios
'auto_install': False,
'installable': False,
'images': []
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################

from openerp.osv import orm


class easy_reconcile_advanced_transaction_ref(orm.TransientModel):

Expand All @@ -35,10 +35,10 @@ def _skip_line(self, cr, uid, rec, move_line, context=None):
return not (move_line.get('transaction_ref') and
move_line.get('partner_id'))

def _matchers(self, cr, uid, rec, move_line, context=None):
def _matchers(self, cr, uid, rec, move_line, context=None):
return (('partner_id', move_line['partner_id']),
('ref', move_line['transaction_ref'].lower().strip()))

def _opposite_matchers(self, cr, uid, rec, move_line, context=None):
yield ('partner_id', move_line['partner_id'])
yield ('ref', (move_line['transaction_ref'] or '').lower().strip())
Expand Down
Loading