From 9f791c81392069e1e82866a9807c2d8c64dcbeef Mon Sep 17 00:00:00 2001 From: "Guewen Baconnier @ Camptocamp" Date: Mon, 22 Oct 2012 13:10:29 +0200 Subject: [PATCH] [IMP] wording: loopup date -> controlling date (lp:c2c-addons/6.1 rev 89.1.2) --- account_credit_control/account.py | 16 ++++----- account_credit_control/line.py | 16 ++++----- account_credit_control/policy.py | 54 +++++++++++++++---------------- account_credit_control/run.py | 8 ++--- 4 files changed, 47 insertions(+), 47 deletions(-) diff --git a/account_credit_control/account.py b/account_credit_control/account.py index b71928fab..2b318dc5d 100644 --- a/account_credit_control/account.py +++ b/account_credit_control/account.py @@ -123,7 +123,7 @@ class AccountMoveLine(Model): _columns = {'invoice_id': fields.many2one('account.invoice', 'Invoice')} - def _get_payment_and_credit_lines(self, moveline_array, lookup_date): + def _get_payment_and_credit_lines(self, moveline_array, controlling_date): credit_lines = [] payment_lines = [] for line in moveline_array: @@ -172,9 +172,9 @@ class AccountMoveLine(Model): applicable_payment.append(pay_line) return applicable_payment - def _compute_partial_reconcile_residual(self, move_lines, lookup_date, move_id, memoizer): + def _compute_partial_reconcile_residual(self, move_lines, controlling_date, move_id, memoizer): """ Compute open amount of multiple credit lines linked to multiple payment lines""" - credit_lines, payment_lines = self._get_payment_and_credit_lines(move_lines, lookup_date, memoizer) + credit_lines, payment_lines = self._get_payment_and_credit_lines(move_lines, controlling_date, memoizer) self._validate_line_currencies(credit_lines) self._validate_line_currencies(payment_lines) self._validate_partial(credit_lines) @@ -194,17 +194,17 @@ class AccountMoveLine(Model): rest = 0.0 return memoizer - def _compute_fully_open_amount(self, move_lines, lookup_date, move_id, memoizer): + def _compute_fully_open_amount(self, move_lines, controlling_date, move_id, memoizer): for move_line in move_lines: memoizer[move_id][move_line.id] = self._get_value_amount(move_line) return memoizer - def _amount_residual_from_date(self, cursor, uid, mv_line_br, lookup_date, context=None): + def _amount_residual_from_date(self, cursor, uid, mv_line_br, controlling_date, context=None): """ Code from function _amount_residual of account/account_move_line.py does not take in account mulitple line payment and reconciliation. We have to rewrite it - Code computes residual amount at lookup date for mv_line_br in entry + Code computes residual amount at controlling date for mv_line_br in entry """ memoizer = run.memoizers['credit_line_residuals'] move_id = mv_line_br.move_id.id @@ -214,8 +214,8 @@ class AccountMoveLine(Model): memoizer[move_id] = {} move_lines = mv_line_br.move_id.line_id if mv_line_br.reconcile_partial_id: - self._compute_partial_reconcile_residual(move_lines, lookup_date, move_id, memoizer) + self._compute_partial_reconcile_residual(move_lines, controlling_date, move_id, memoizer) else: - self._compute_fully_open_amount(move_lines, lookup_date, move_id, memoizer) + self._compute_fully_open_amount(move_lines, controlling_date, move_id, memoizer) return memoizer[move_id][mv_line_br.id] diff --git a/account_credit_control/line.py b/account_credit_control/line.py index db5486833..a969391a5 100644 --- a/account_credit_control/line.py +++ b/account_credit_control/line.py @@ -107,18 +107,18 @@ class CreditControlLine (Model): _defaults = {'state': 'draft'} def _update_from_mv_line(self, cursor, uid, ids, mv_line_br, level, - lookup_date, context=None): + controlling_date, context=None): """hook function to update line if required""" context = context or {} return [] def _create_from_mv_line(self, cursor, uid, ids, mv_line_br, - level, lookup_date, context=None): + level, controlling_date, context=None): """Create credit line""" acc_line_obj = self.pool.get('account.move.line') context = context or {} data_dict = {} - data_dict['date'] = lookup_date + data_dict['date'] = controlling_date data_dict['date_due'] = mv_line_br.date_maturity data_dict['state'] = 'draft' data_dict['canal'] = level.canal @@ -128,7 +128,7 @@ class CreditControlLine (Model): data_dict['amount_due'] = (mv_line_br.amount_currency or mv_line_br.debit or mv_line_br.credit) data_dict['balance_due'] = acc_line_obj._amount_residual_from_date(cursor, uid, mv_line_br, - lookup_date, context=context) + controlling_date, context=context) data_dict['policy_level_id'] = level.id data_dict['company_id'] = mv_line_br.company_id.id data_dict['move_line_id'] = mv_line_br.id @@ -136,7 +136,7 @@ class CreditControlLine (Model): def create_or_update_from_mv_lines(self, cursor, uid, ids, lines, - level_id, lookup_date, errors=None, context=None): + level_id, controlling_date, errors=None, context=None): """Create or update line base on levels""" context = context or {} currency_obj = self.pool.get('res.currency') @@ -166,17 +166,17 @@ class CreditControlLine (Model): if line.id in existings: # does nothing just a hook credit_line_ids += self._update_from_mv_line(local_cr, uid, ids, - line, level, lookup_date, + line, level, controlling_date, context=context) else: # as we use memoizer pattern this has almost no cost to get it # multiple time open_amount = acc_line_obj._amount_residual_from_date(cursor, uid, line, - lookup_date, context=context) + controlling_date, context=context) if open_amount > tolerance.get(line.currency_id.id, tolerance_base): credit_line_ids += self._create_from_mv_line(local_cr, uid, ids, - line, level, lookup_date, + line, level, controlling_date, context=context) except Exception, exc: logger.error(exc) diff --git a/account_credit_control/policy.py b/account_credit_control/policy.py index 2c10dd2f4..b5be24d41 100644 --- a/account_credit_control/policy.py +++ b/account_credit_control/policy.py @@ -40,7 +40,7 @@ class CreditControlPolicy(Model): } - def _get_account_related_lines(self, cursor, uid, policy_id, lookup_date, lines, context=None): + def _get_account_related_lines(self, cursor, uid, policy_id, controlling_date, lines, context=None): """ We get all the lines related to accounts with given credit policy. We try not to use direct SQL in order to respect security rules. As we define the first set it is important, The date is used to do a prefilter. @@ -53,7 +53,7 @@ class CreditControlPolicy(Model): if not acc_ids: return lines move_ids = move_l_obj.search(cursor, uid, [('account_id', 'in', acc_ids), - ('date_maturity', '<=', lookup_date), + ('date_maturity', '<=', controlling_date), ('reconcile_id', '=', False), ('partner_id', '!=', False)]) @@ -61,7 +61,7 @@ class CreditControlPolicy(Model): return lines - def _get_sum_reduce_range(self, cursor, uid, policy_id, lookup_date, lines, model, + def _get_sum_reduce_range(self, cursor, uid, policy_id, controlling_date, lines, model, move_relation_field, context=None): """ We get all the lines related to the model with given credit policy. We also reduce from the global set (lines) the move line to be excluded. @@ -79,7 +79,7 @@ class CreditControlPolicy(Model): add_obj_ids = my_obj.search(cursor, uid, [('credit_policy_id', '=', policy_id)]) if add_obj_ids: add_lines = move_l_obj.search(cursor, uid, [(move_relation_field, 'in', add_obj_ids), - ('date_maturity', '<=', lookup_date), + ('date_maturity', '<=', controlling_date), ('partner_id', '!=', False), ('reconcile_id', '=', False)]) lines = list(set(lines + add_lines)) @@ -90,7 +90,7 @@ class CreditControlPolicy(Model): if neg_obj_ids: # should we add ('id', 'in', lines) in domain ? it may give a veeery long SQL... neg_lines = move_l_obj.search(cursor, uid, [(move_relation_field, 'in', neg_obj_ids), - ('date_maturity', '<=', lookup_date), + ('date_maturity', '<=', controlling_date), ('partner_id', '!=', False), ('reconcile_id', '=', False)]) if neg_lines: @@ -98,17 +98,17 @@ class CreditControlPolicy(Model): return lines - def _get_partner_related_lines(self, cursor, uid, policy_id, lookup_date, lines, context=None): - return self._get_sum_reduce_range(cursor, uid, policy_id, lookup_date, lines, + def _get_partner_related_lines(self, cursor, uid, policy_id, controlling_date, lines, context=None): + return self._get_sum_reduce_range(cursor, uid, policy_id, controlling_date, lines, 'res.partner', 'partner_id', context=context) - def _get_invoice_related_lines(self, cursor, uid, policy_id, lookup_date, lines, context=None): - return self._get_sum_reduce_range(cursor, uid, policy_id, lookup_date, lines, + def _get_invoice_related_lines(self, cursor, uid, policy_id, controlling_date, lines, context=None): + return self._get_sum_reduce_range(cursor, uid, policy_id, controlling_date, lines, 'account.invoice', 'invoice', context=context) - def _get_moves_line_to_process(self, cursor, uid, policy_id, lookup_date, context=None): + def _get_moves_line_to_process(self, cursor, uid, policy_id, controlling_date, context=None): """Retrive all the move line to be procces for current policy. This function is planned to be use only on one id. Priority of inclustion, exlusion is account, partner, invoice""" @@ -118,11 +118,11 @@ class CreditControlPolicy(Model): policy_id = policy_id[0] # order of call MUST be respected priority is account, partner, invoice lines = self._get_account_related_lines(cursor, uid, policy_id, - lookup_date, lines, context=context) + controlling_date, lines, context=context) lines = self._get_partner_related_lines(cursor, uid, policy_id, - lookup_date, lines, context=context) + controlling_date, lines, context=context) lines = self._get_invoice_related_lines(cursor, uid, policy_id, - lookup_date, lines, context=context) + controlling_date, lines, context=context) return lines def _check_lines_policies(self, cursor, uid, policy_id, lines, context=None): @@ -217,18 +217,18 @@ class CreditControlPolicyLevel(Model): # ----- time related functions --------- def _net_days_get_boundary(self): - return " (mv_line.date_maturity + %(delay)s)::date <= date(%(lookup_date)s)" + return " (mv_line.date_maturity + %(delay)s)::date <= date(%(controlling_date)s)" def _end_of_month_get_boundary(self): return ("(date_trunc('MONTH', (mv_line.date_maturity + %(delay)s))+INTERVAL '1 MONTH - 1 day')::date" - "<= date(%(lookup_date)s)") + "<= date(%(controlling_date)s)") def _previous_date_get_boundary(self): - return "(cr_line.date + %(delay)s)::date <= date(%(lookup_date)s)" + return "(cr_line.date + %(delay)s)::date <= date(%(controlling_date)s)" - def _get_sql_date_boundary_for_computation_mode(self, cursor, uid, level, lookup_date, context=None): + def _get_sql_date_boundary_for_computation_mode(self, cursor, uid, level, controlling_date, context=None): """Return a where clauses statement for the given - lookup date and computation mode of the level""" + controlling date and computation mode of the level""" fname = "_%s_get_boundary" % (level.computation_mode,) if hasattr(self, fname): fnc = getattr(self, fname) @@ -239,7 +239,7 @@ class CreditControlPolicyLevel(Model): # ----------------------------------------- - def _get_first_level_lines(self, cursor, uid, level, lookup_date, lines, context=None): + def _get_first_level_lines(self, cursor, uid, level, controlling_date, lines, context=None): if not lines: return [] """Retrieve all the line that are linked to a frist level. @@ -251,8 +251,8 @@ class CreditControlPolicyLevel(Model): " AND NOT EXISTS (SELECT cr_line.id from credit_control_line cr_line\n" " WHERE cr_line.move_line_id = mv_line.id)") sql += " AND" + self._get_sql_date_boundary_for_computation_mode( - cursor, uid, level, lookup_date, context) - data_dict = {'lookup_date': lookup_date, 'line_ids': tuple(lines), + cursor, uid, level, controlling_date, context) + data_dict = {'controlling_date': controlling_date, 'line_ids': tuple(lines), 'delay': level.delay_days} cursor.execute(sql, data_dict) @@ -262,7 +262,7 @@ class CreditControlPolicyLevel(Model): return [x[0] for x in res] - def _get_other_level_lines(self, cursor, uid, level, lookup_date, lines, context=None): + def _get_other_level_lines(self, cursor, uid, level, controlling_date, lines, context=None): # We filter line that have a level smaller than current one # TODO if code fits need refactor _get_first_level_lines and _get_other_level_lines # Code is not DRY @@ -278,12 +278,12 @@ class CreditControlPolicyLevel(Model): " AND cr_line.level = %(level)s\n" " AND mv_line.id in %(line_ids)s\n") sql += " AND " + self._get_sql_date_boundary_for_computation_mode( - cursor, uid, level, lookup_date, context) + cursor, uid, level, controlling_date, context) previous_level_id = self._previous_level( cursor, uid, level, context=context) previous_level = self.browse( cursor, uid, previous_level_id, context=context) - data_dict = {'lookup_date': lookup_date, 'line_ids': tuple(lines), + data_dict = {'controlling_date': controlling_date, 'line_ids': tuple(lines), 'delay': level.delay_days, 'level': previous_level.level} cursor.execute(sql, data_dict) @@ -292,7 +292,7 @@ class CreditControlPolicyLevel(Model): return [] return [x[0] for x in res] - def get_level_lines(self, cursor, uid, level_id, lookup_date, lines, context=None): + def get_level_lines(self, cursor, uid, level_id, controlling_date, lines, context=None): """get all move lines in entry lines that match the current level""" assert not (isinstance(level_id, list) and len(level_id) > 1), "level_id: only one id expected" if isinstance(level_id, list): @@ -301,10 +301,10 @@ class CreditControlPolicyLevel(Model): level = self.browse(cursor, uid, level_id, context=context) if self._previous_level(cursor, uid, level, context=context) is None: matching_lines += self._get_first_level_lines( - cursor, uid, level, lookup_date, lines, context=context) + cursor, uid, level, controlling_date, lines, context=context) else: matching_lines += self._get_other_level_lines( - cursor, uid, level, lookup_date, lines, context=context) + cursor, uid, level, controlling_date, lines, context=context) return matching_lines diff --git a/account_credit_control/run.py b/account_credit_control/run.py index 80e58798e..c6b2bdb74 100644 --- a/account_credit_control/run.py +++ b/account_credit_control/run.py @@ -37,7 +37,7 @@ class CreditControlRun(Model): _name = "credit.control.run" _rec_name = 'date' _description = """Credit control line generator""" - _columns = {'date': fields.date('Lookup date', required=True), + _columns = {'date': fields.date('Controlling date', required=True), 'policy_ids': fields.many2many('credit.control.policy', rel="credit_run_policy_rel", string='Policies', @@ -64,10 +64,10 @@ class CreditControlRun(Model): _defaults = {'state': 'draft'} - def check_run_date(self, cursor, uid, ids, lookup_date, context=None): - """Ensure that there is no credit line in the future using lookup_date""" + def check_run_date(self, cursor, uid, ids, controlling_date, context=None): + """Ensure that there is no credit line in the future using controlling_date""" line_obj = self.pool.get('credit.control.line') - lines = line_obj.search(cursor, uid, [('date', '>', lookup_date)], + lines = line_obj.search(cursor, uid, [('date', '>', controlling_date)], order='date DESC', limit=1) if lines: line = line_obj.browse(cursor, uid, lines[0])