From 4a1c950044619bc8fd39cfee0e672e33b37bce1a Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Mon, 4 Aug 2014 17:00:09 +0200 Subject: [PATCH] [IMP] account_easy_reconcile: Fix PEP8 --- account_easy_reconcile/base_reconciliation.py | 16 ++----- account_easy_reconcile/easy_reconcile.py | 45 ++++++++----------- .../easy_reconcile_history.py | 13 ++---- .../simple_reconciliation.py | 19 ++------ 4 files changed, 29 insertions(+), 64 deletions(-) diff --git a/account_easy_reconcile/base_reconciliation.py b/account_easy_reconcile/base_reconciliation.py index d774455f..6145720a 100644 --- a/account_easy_reconcile/base_reconciliation.py +++ b/account_easy_reconcile/base_reconciliation.py @@ -23,7 +23,7 @@ from openerp.osv import fields, orm from operator import itemgetter, attrgetter -class easy_reconcile_base(orm.AbstractModel): +class EasyReconcileBase(orm.AbstractModel): """Abstract Model for reconciliation methods""" @@ -88,7 +88,6 @@ class easy_reconcile_base(orm.AbstractModel): # which returns a list, we have to # accomodate with that 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])) @@ -116,14 +115,13 @@ class easy_reconcile_base(orm.AbstractModel): for key, value in line.iteritems() if key in keys), lines) - debit, credit = sums['debit'], sums['credit'] writeoff_amount = round(debit - credit, precision) return bool(writeoff_limit >= abs(writeoff_amount)), debit, credit def _get_rec_date(self, cr, uid, rec, lines, based_on='end_period_last_credit', context=None): - period_obj = self.pool.get('account.period') + period_obj = self.pool['account.period'] def last_period(mlines): period_ids = [ml['period_id'] for ml in mlines] @@ -154,7 +152,8 @@ class easy_reconcile_base(orm.AbstractModel): # when date is None return None - def _reconcile_lines(self, cr, uid, rec, lines, allow_partial=False, context=None): + def _reconcile_lines(self, cr, uid, rec, lines, allow_partial=False, + context=None): """ Try to reconcile given lines :param list lines: list of dict of move lines, they must at least @@ -169,29 +168,23 @@ class easy_reconcile_base(orm.AbstractModel): """ if context is None: context = {} - ml_obj = self.pool.get('account.move.line') writeoff = rec.write_off - line_ids = [l['id'] for l in lines] 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, rec.date_base_on, context=context) - rec_ctx = dict(context, date_p=date) if below_writeoff: if sum_credit < sum_debit: writeoff_account_id = rec.account_profit_id.id else: writeoff_account_id = rec.account_lost_id.id - period_id = self.pool.get('account.period').find( cr, uid, dt=date, context=context)[0] - if rec.analytic_account_id: rec_ctx['analytic_id'] = rec.analytic_account_id.id - ml_obj.reconcile( cr, uid, line_ids, @@ -208,5 +201,4 @@ class easy_reconcile_base(orm.AbstractModel): type='manual', context=rec_ctx) return True, False - return False, False diff --git a/account_easy_reconcile/easy_reconcile.py b/account_easy_reconcile/easy_reconcile.py index f5529b84..105d06a4 100644 --- a/account_easy_reconcile/easy_reconcile.py +++ b/account_easy_reconcile/easy_reconcile.py @@ -22,11 +22,9 @@ from openerp.osv import fields, osv, orm from openerp.tools.translate import _ from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT -from openerp.tools.translate import _ -class easy_reconcile_options(orm.AbstractModel): - +class EasyReconcileOptions(orm.AbstractModel): """Options of a reconciliation profile Columns shared by the configuration of methods @@ -38,12 +36,14 @@ class easy_reconcile_options(orm.AbstractModel): _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'), - ('newest', 'Most recent move line'), - ('actual', 'Today'), - ('end_period', 'End of period of most recent move line'), - ('newest_credit', 'Date of most recent credit'), - ('newest_debit', 'Date of most recent debit')] + return [ + ('end_period_last_credit', 'End of period of most recent credit'), + ('newest', 'Most recent move line'), + ('actual', 'Today'), + ('end_period', 'End of period of most recent move line'), + ('newest_credit', 'Date of most recent credit'), + ('newest_debit', 'Date of most recent debit') + ] _columns = { 'write_off': fields.float('Write off allowed'), @@ -69,13 +69,10 @@ class easy_reconcile_options(orm.AbstractModel): } -class account_easy_reconcile_method(orm.Model): - +class AccountEasyReconcileMethod(orm.Model): _name = 'account.easy.reconcile.method' _description = 'reconcile method for account_easy_reconcile' - _inherit = 'easy.reconcile.options' - _order = 'sequence' def _get_all_rec_method(self, cr, uid, context=None): @@ -132,7 +129,7 @@ class account_easy_reconcile_method(orm.Model): """) -class account_easy_reconcile(orm.Model): +class AccountEasyReconcile(orm.Model): _name = 'account.easy.reconcile' _description = 'account easy reconcile' @@ -261,7 +258,7 @@ class account_easy_reconcile(orm.Model): be called when there is no history on the reconciliation task. """ - raise osv.except_osv( + raise orm.except_orm( _('Error'), _('There is no history of reconciled ' 'items on the task: %s.') % rec.name) @@ -280,14 +277,10 @@ class account_easy_reconcile(orm.Model): } def open_unreconcile(self, cr, uid, ids, context=None): - """ Open the view of move line with the unreconciled move lines - """ - + """ Open the view of move line with the unreconciled move lines""" assert len(ids) == 1, \ "You can only open entries from one profile at a time" - obj_move_line = self.pool.get('account.move.line') - res = {} for task in self.browse(cr, uid, ids, context=context): line_ids = obj_move_line.search( cr, uid, @@ -297,17 +290,14 @@ class account_easy_reconcile(orm.Model): context=context) name = _('Unreconciled items') - return self._open_move_line_list(cr, uid, line_ids, name, context=context) + return self._open_move_line_list(cr, uid, line_ids, name, + context=context) def open_partial_reconcile(self, cr, uid, ids, context=None): - """ Open the view of move line with the unreconciled move lines - """ - + """ Open the view of move line with the unreconciled move lines""" assert len(ids) == 1, \ "You can only open entries from one profile at a time" - obj_move_line = self.pool.get('account.move.line') - res = {} for task in self.browse(cr, uid, ids, context=context): line_ids = obj_move_line.search( cr, uid, @@ -316,7 +306,8 @@ class account_easy_reconcile(orm.Model): ('reconcile_partial_id', '!=', False)], context=context) name = _('Partial reconciled items') - return self._open_move_line_list(cr, uid, line_ids, name, context=context) + return self._open_move_line_list(cr, uid, line_ids, name, + context=context) def last_history_reconcile(self, cr, uid, rec_id, context=None): """ Get the last history record for this reconciliation profile diff --git a/account_easy_reconcile/easy_reconcile_history.py b/account_easy_reconcile/easy_reconcile_history.py index f397b820..67581cb7 100644 --- a/account_easy_reconcile/easy_reconcile_history.py +++ b/account_easy_reconcile/easy_reconcile_history.py @@ -23,8 +23,7 @@ from openerp.osv import orm, fields from openerp.tools.translate import _ -class easy_reconcile_history(orm.Model): - +class EasyReconcileHistory(orm.Model): """ Store an history of the runs per profile Each history stores the list of reconciliations done""" @@ -34,10 +33,8 @@ class easy_reconcile_history(orm.Model): def _reconcile_line_ids(self, cr, uid, ids, name, args, context=None): result = {} - for history in self.browse(cr, uid, ids, context=context): result[history.id] = {} - move_line_ids = [] for reconcile in history.reconcile_ids: move_line_ids += [line.id @@ -51,7 +48,6 @@ class easy_reconcile_history(orm.Model): for line in reconcile.line_partial_ids] result[history.id]['partial_line_ids'] = move_line_ids - return result _columns = { @@ -91,7 +87,8 @@ class easy_reconcile_history(orm.Model): } - def _open_move_lines(self, cr, uid, history_id, rec_type='full', context=None): + def _open_move_lines(self, cr, uid, history_id, rec_type='full', + context=None): """ For an history record, open the view of move line with the reconciled or partially reconciled move lines @@ -101,18 +98,14 @@ class easy_reconcile_history(orm.Model): """ assert rec_type in ('full', 'partial'), \ "rec_type must be 'full' or 'partial'" - history = self.browse(cr, uid, history_id, context=context) - if rec_type == 'full': field = 'reconcile_line_ids' name = _('Reconciliations') else: field = 'partial_line_ids' name = _('Partial Reconciliations') - move_line_ids = [line.id for line in getattr(history, field)] - return { 'name': name, 'view_mode': 'tree,form', diff --git a/account_easy_reconcile/simple_reconciliation.py b/account_easy_reconcile/simple_reconciliation.py index ac3810e9..f108ff4f 100644 --- a/account_easy_reconcile/simple_reconciliation.py +++ b/account_easy_reconcile/simple_reconciliation.py @@ -22,8 +22,7 @@ from openerp.osv.orm import AbstractModel, TransientModel -class easy_reconcile_simple(AbstractModel): - +class EasyReconcileSimple(AbstractModel): _name = 'easy.reconcile.simple' _inherit = 'easy.reconcile.base' @@ -32,20 +31,14 @@ class easy_reconcile_simple(AbstractModel): _key_field = None def rec_auto_lines_simple(self, cr, uid, rec, lines, context=None): - if context is None: - context = {} - if self._key_field is None: raise ValueError("_key_field has to be defined") - count = 0 res = [] while (count < len(lines)): for i in xrange(count + 1, len(lines)): - writeoff_account_id = False if lines[count][self._key_field] != lines[i][self._key_field]: break - check = False if lines[count]['credit'] > 0 and lines[i]['debit'] > 0: credit_line = lines[count] @@ -57,7 +50,6 @@ class easy_reconcile_simple(AbstractModel): check = True if not check: continue - reconciled, dummy = self._reconcile_lines( cr, uid, rec, [credit_line, debit_line], allow_partial=False, context=context) @@ -90,8 +82,7 @@ class easy_reconcile_simple(AbstractModel): return self.rec_auto_lines_simple(cr, uid, rec, lines, context) -class easy_reconcile_simple_name(TransientModel): - +class EasyReconcileSimpleName(TransientModel): _name = 'easy.reconcile.simple.name' _inherit = 'easy.reconcile.simple' @@ -100,8 +91,7 @@ class easy_reconcile_simple_name(TransientModel): _key_field = 'name' -class easy_reconcile_simple_partner(TransientModel): - +class EasyReconcileSimplePartner(TransientModel): _name = 'easy.reconcile.simple.partner' _inherit = 'easy.reconcile.simple' @@ -110,8 +100,7 @@ class easy_reconcile_simple_partner(TransientModel): _key_field = 'partner_id' -class easy_reconcile_simple_reference(TransientModel): - +class EasyReconcileSimpleReference(TransientModel): _name = 'easy.reconcile.simple.reference' _inherit = 'easy.reconcile.simple'