diff --git a/account_credit_control/account.py b/account_credit_control/account.py index 44e422222..9e4939931 100644 --- a/account_credit_control/account.py +++ b/account_credit_control/account.py @@ -55,10 +55,10 @@ class AccountInvoice(Model): readonly=True) } - def action_move_create(self, cursor, uid, ids, context=None): + def action_move_create(self, cr, uid, ids, context=None): """ Write the id of the invoice in the generated moves. """ - res = super(AccountInvoice, self).action_move_create(cursor, uid, ids, context=context) - for inv in self.browse(cursor, uid, ids, context=context): + res = super(AccountInvoice, self).action_move_create(cr, uid, ids, context=context) + for inv in self.browse(cr, uid, ids, context=context): if inv.move_id: for line in inv.move_id.line_id: line.write({'invoice_id': inv.id}) diff --git a/account_credit_control/line.py b/account_credit_control/line.py index 41129d010..c1e3542b1 100644 --- a/account_credit_control/line.py +++ b/account_credit_control/line.py @@ -111,12 +111,12 @@ class CreditControlLine(Model): _defaults = {'state': 'draft'} - def _update_from_mv_line(self, cursor, uid, ids, mv_line_br, level, + def _update_from_mv_line(self, cr, uid, ids, mv_line_br, level, controlling_date, context=None): """hook function to update line if required""" return [] - def _prepare_from_move_line(self, cursor, uid, move_line, + def _prepare_from_move_line(self, cr, uid, move_line, level, controlling_date, open_amount, context=None): """Create credit control line""" @@ -136,48 +136,48 @@ class CreditControlLine(Model): data['move_line_id'] = move_line.id return data - def create_or_update_from_mv_lines(self, cursor, uid, ids, lines, + def create_or_update_from_mv_lines(self, cr, uid, ids, lines, level_id, controlling_date, context=None): """Create or update line base on levels""" currency_obj = self.pool.get('res.currency') level_obj = self.pool.get('credit.control.policy.level') ml_obj = self.pool.get('account.move.line') - level = level_obj.browse(cursor, uid, level_id, context) + level = level_obj.browse(cr, uid, level_id, context) current_lvl = level.level debit_line_ids = [] - user = self.pool.get('res.users').browse(cursor, uid, uid) + user = self.pool.get('res.users').browse(cr, uid, uid) tolerance_base = user.company_id.credit_control_tolerance - currency_ids = currency_obj.search(cursor, uid, [], context=context) + currency_ids = currency_obj.search(cr, uid, [], context=context) tolerance = {} acc_line_obj = self.pool.get('account.move.line') for c_id in currency_ids: tolerance[c_id] = currency_obj.compute( - cursor, uid, + cr, uid, c_id, user.company_id.currency_id.id, tolerance_base, context=context) existings = self.search( - cursor, uid, + cr, uid, [('move_line_id', 'in', lines), ('level', '=', current_lvl)], context=context) - for line in ml_obj.browse(cursor, uid, lines, context): + for line in ml_obj.browse(cr, uid, lines, context): if line.id in existings: # does nothing just a hook debit_line_ids += self._update_from_mv_line( - cursor, uid, ids, line, level, + cr, uid, ids, line, level, controlling_date, context=context) else: open_amount = line.amount_residual_currency if open_amount > tolerance.get(line.currency_id.id, tolerance_base): vals = self._prepare_from_move_line( - cursor, uid, line, level, controlling_date, open_amount, context=context) - debit_line_ids.append(self.create(cursor, uid, vals, context=context)) + cr, uid, line, level, controlling_date, open_amount, context=context) + debit_line_ids.append(self.create(cr, uid, vals, context=context)) return debit_line_ids diff --git a/account_credit_control/policy.py b/account_credit_control/policy.py index 34f8d1e95..6630b8668 100644 --- a/account_credit_control/policy.py +++ b/account_credit_control/policy.py @@ -47,7 +47,7 @@ class CreditControlPolicy(Model): help='This policy will be active only for the selected accounts'), } - def _move_lines_domain(self, cursor, uid, policy, controlling_date, context=None): + def _move_lines_domain(self, cr, uid, policy, controlling_date, context=None): """Build the default domain for searching move lines""" account_ids = [a.id for a in policy.account_ids] return [('account_id', 'in', account_ids), @@ -55,7 +55,7 @@ class CreditControlPolicy(Model): ('reconcile_id', '=', False), ('partner_id', '!=', False)] - def _due_move_lines(self, cursor, uid, policy, controlling_date, context=None): + def _due_move_lines(self, cr, uid, policy, controlling_date, context=None): """ Get the due move lines for the policy of the company. The set of ids will be reduced and extended according to the specific policies @@ -67,16 +67,16 @@ class CreditControlPolicy(Model): accounts used in the policy are reconcilable. """ move_l_obj = self.pool.get('account.move.line') - user = self.pool.get('res.users').browse(cursor, uid, uid, context=context) + user = self.pool.get('res.users').browse(cr, uid, uid, context=context) if user.company_id.credit_policy_id.id != policy.id: return set() return set(move_l_obj.search( - cursor, uid, - self._move_lines_domain(cursor, uid, policy, controlling_date, context=context), + cr, uid, + self._move_lines_domain(cr, uid, policy, controlling_date, context=context), context=context)) - def _move_lines_subset(self, cursor, uid, policy, controlling_date, + def _move_lines_subset(self, cr, uid, policy, controlling_date, model, move_relation_field, context=None): """ Get the move lines related to one model for a policy. @@ -99,7 +99,7 @@ class CreditControlPolicy(Model): my_obj = self.pool.get(model) move_l_obj = self.pool.get('account.move.line') - default_domain = self._move_lines_domain(cursor, uid, policy, controlling_date, context=context) + default_domain = self._move_lines_domain(cr, uid, policy, controlling_date, context=context) to_add_ids = set() to_remove_ids = set() @@ -107,28 +107,28 @@ class CreditControlPolicy(Model): # run for this policy. # If another object override the credit_policy_id (ie. invoice after add_obj_ids = my_obj.search( - cursor, uid, + cr, uid, [('credit_policy_id', '=', policy.id)], context=context) if add_obj_ids: domain = list(default_domain) domain.append((move_relation_field, 'in', add_obj_ids)) - to_add_ids = set(move_l_obj.search(cursor, uid, domain, context=context)) + to_add_ids = set(move_l_obj.search(cr, uid, domain, context=context)) # The lines which are linked to another policy do not have to be # included in the run for this policy. neg_obj_ids = my_obj.search( - cursor, uid, + cr, uid, [('credit_policy_id', '!=', policy.id), ('credit_policy_id', '!=', False)], context=context) if neg_obj_ids: domain = list(default_domain) domain.append((move_relation_field, 'in', neg_obj_ids)) - to_remove_ids = set(move_l_obj.search(cursor, uid, domain, context=context)) + to_remove_ids = set(move_l_obj.search(cr, uid, domain, context=context)) return to_add_ids, to_remove_ids - def _get_partner_related_lines(self, cursor, uid, policy, controlling_date, context=None): + def _get_partner_related_lines(self, cr, uid, policy, controlling_date, context=None): """ Get the move lines for a policy related to a partner. :param browse_record policy: policy @@ -140,10 +140,10 @@ class CreditControlPolicy(Model): the process """ return self._move_lines_subset( - cursor, uid, policy, controlling_date, + cr, uid, policy, controlling_date, 'res.partner', 'partner_id', context=context) - def _get_invoice_related_lines(self, cursor, uid, policy, controlling_date, context=None): + def _get_invoice_related_lines(self, cr, uid, policy, controlling_date, context=None): """ Get the move lines for a policy related to an invoice. :param browse_record policy: policy @@ -155,10 +155,10 @@ class CreditControlPolicy(Model): the process """ return self._move_lines_subset( - cursor, uid, policy, controlling_date, + cr, uid, policy, controlling_date, 'account.invoice', 'invoice', context=context) - def _get_move_lines_to_process(self, cursor, uid, policy_id, controlling_date, context=None): + def _get_move_lines_to_process(self, cr, uid, policy_id, controlling_date, context=None): """Build a list of move lines ids to include in a run for a policy at a given date. :param int/long policy: id of the policy @@ -170,20 +170,20 @@ class CreditControlPolicy(Model): if isinstance(policy_id, list): policy_id = policy_id[0] - policy = self.browse(cursor, uid, policy_id, context=context) + policy = self.browse(cr, uid, policy_id, context=context) # there is a priority between the lines, depicted by the calls below # warning, side effect method called on lines lines = self._due_move_lines( - cursor, uid, policy, controlling_date, context=context) + cr, uid, policy, controlling_date, context=context) add_ids, remove_ids = self._get_partner_related_lines( - cursor, uid, policy, controlling_date, context=context) + cr, uid, policy, controlling_date, context=context) lines = lines.union(add_ids).difference(remove_ids) add_ids, remove_ids = self._get_invoice_related_lines( - cursor, uid, policy, controlling_date, context=context) + cr, uid, policy, controlling_date, context=context) lines = lines.union(add_ids).difference(remove_ids) return lines - def _lines_different_policy(self, cursor, uid, policy_id, lines, context=None): + def _lines_different_policy(self, cr, uid, policy_id, lines, context=None): """ Return a set of move lines ids for which there is an existing credit line but with a different policy. """ @@ -194,10 +194,10 @@ class CreditControlPolicy(Model): "policy_id: only one id expected" if isinstance(policy_id, list): policy_id = policy_id[0] - cursor.execute("SELECT move_line_id FROM credit_control_line" + cr.execute("SELECT move_line_id FROM credit_control_line" " WHERE policy_id != %s and move_line_id in %s", (policy_id, tuple(lines))) - res = cursor.fetchall() + res = cr.fetchall() if res: different_lines.update([x[0] for x in res]) return different_lines @@ -231,17 +231,17 @@ class CreditControlPolicyLevel(Model): 'custom_text': fields.text('Custom Message', required=True, translate=True), } - def _check_level_mode(self, cursor, uid, rids, context=None): + def _check_level_mode(self, cr, uid, rids, context=None): """ The smallest level of a policy cannot be computed on the "previous_date". Return False if this happens. """ if isinstance(rids, (int, long)): rids = [rids] - for level in self.browse(cursor, uid, rids, context): + for level in self.browse(cr, uid, rids, context): smallest_level_id = self.search( - cursor, uid, + cr, uid, [('policy_id', '=', level.policy_id.id)], order='level asc', limit=1, context=context) - smallest_level = self.browse(cursor, uid, smallest_level_id[0], context) + smallest_level = self.browse(cr, uid, smallest_level_id[0], context) if smallest_level.computation_mode == 'previous_date': return False return True @@ -254,7 +254,7 @@ class CreditControlPolicyLevel(Model): 'The smallest level can not be of type Previous Reminder', ['level'])] - def _previous_level(self, cursor, uid, policy_level, context=None): + def _previous_level(self, cr, uid, policy_level, context=None): """ For one policy level, returns the id of the previous level If there is no previous level, it returns None, it means that's the @@ -264,7 +264,7 @@ class CreditControlPolicyLevel(Model): :return: previous level id or None if there is no previous level """ previous_level_ids = self.search( - cursor, + cr, uid, [('policy_id', '=', policy_level.policy_id.id), ('level', '<', policy_level.level)], @@ -285,7 +285,7 @@ class CreditControlPolicyLevel(Model): def _previous_date_get_boundary(self): return "(cr_line.date + %(delay)s)::date <= date(%(controlling_date)s)" - def _get_sql_date_boundary_for_computation_mode(self, cursor, uid, level, controlling_date, context=None): + def _get_sql_date_boundary_for_computation_mode(self, cr, uid, level, controlling_date, context=None): """Return a where clauses statement for the given controlling date and computation mode of the level""" fname = "_%s_get_boundary" % (level.computation_mode,) @@ -298,7 +298,7 @@ class CreditControlPolicyLevel(Model): # ----------------------------------------- - def _get_first_level_lines(self, cursor, uid, level, controlling_date, lines, context=None): + def _get_first_level_lines(self, cr, uid, level, controlling_date, lines, context=None): """Retrieve all the move lines that are linked to a first level. We use Raw SQL for performance. Security rule where applied in policy object when the first set of lines were retrieved""" @@ -311,17 +311,17 @@ 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, controlling_date, context) + cr, uid, level, controlling_date, context) data_dict = {'controlling_date': controlling_date, 'line_ids': tuple(lines), 'delay': level.delay_days} - cursor.execute(sql, data_dict) - res = cursor.fetchall() + cr.execute(sql, data_dict) + res = cr.fetchall() if res: level_lines.update([x[0] for x in res]) return level_lines - def _get_other_level_lines(self, cursor, uid, level, controlling_date, lines, context=None): + def _get_other_level_lines(self, cr, uid, level, controlling_date, lines, context=None): """ Retrieve the move lines for other levels than first level. """ level_lines = set() @@ -337,36 +337,36 @@ 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, controlling_date, context) + cr, uid, level, controlling_date, context) previous_level_id = self._previous_level( - cursor, uid, level, context=context) + cr, uid, level, context=context) previous_level = self.browse( - cursor, uid, previous_level_id, context=context) + cr, uid, previous_level_id, context=context) data_dict = {'controlling_date': controlling_date, 'line_ids': tuple(lines), 'delay': level.delay_days, 'level': previous_level.level} - # print cursor.mogrify(sql, data_dict) - cursor.execute(sql, data_dict) - res = cursor.fetchall() + # print cr.mogrify(sql, data_dict) + cr.execute(sql, data_dict) + res = cr.fetchall() if res: level_lines.update([x[0] for x in res]) return level_lines - def get_level_lines(self, cursor, uid, level_id, controlling_date, lines, context=None): + def get_level_lines(self, cr, 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): level_id = level_id[0] matching_lines = set() - level = self.browse(cursor, uid, level_id, context=context) - if self._previous_level(cursor, uid, level, context=context) is None: + level = self.browse(cr, uid, level_id, context=context) + if self._previous_level(cr, uid, level, context=context) is None: method = self._get_first_level_lines else: method = self._get_other_level_lines matching_lines.update( - method(cursor, uid, level, controlling_date, lines, context=context)) + method(cr, 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 a897628ff..b660afb84 100644 --- a/account_credit_control/run.py +++ b/account_credit_control/run.py @@ -61,28 +61,28 @@ class CreditControlRun(Model): readonly=True), } - def _get_policies(self, cursor, uid, context=None): + def _get_policies(self, cr, uid, context=None): return self.pool.get('credit.control.policy').\ - search(cursor, uid, [], context=context) + search(cr, uid, [], context=context) _defaults = { 'state': 'draft', 'policy_ids': _get_policies, } - def _check_run_date(self, cursor, uid, ids, controlling_date, context=None): + def _check_run_date(self, cr, 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', '>', controlling_date)], + lines = line_obj.search(cr, uid, [('date', '>', controlling_date)], order='date DESC', limit=1, context=context) if lines: - line = line_obj.browse(cursor, uid, lines[0], context=context) + line = line_obj.browse(cr, uid, lines[0], context=context) raise except_osv( _('Error'), _('A run has already been executed more recently than %s') % (line.date)) return True - def _generate_credit_lines(self, cursor, uid, run_id, context=None): + def _generate_credit_lines(self, cr, uid, run_id, context=None): """ Generate credit control lines. """ cr_line_obj = self.pool.get('credit.control.line') assert not (isinstance(run_id, list) and len(run_id) > 1), \ @@ -90,7 +90,7 @@ class CreditControlRun(Model): if isinstance(run_id, list): run_id = run_id[0] - run = self.browse(cursor, uid, run_id, context=context) + run = self.browse(cr, uid, run_id, context=context) manually_managed_lines = set() # line who changed policy credit_line_ids = [] # generated lines run._check_run_date(run.date, context=context) @@ -117,7 +117,7 @@ class CreditControlRun(Model): for level in reversed(policy.level_ids): level_lines = level.get_level_lines(run.date, lines, context=context) policy_generated_ids += cr_line_obj.create_or_update_from_mv_lines( - cursor, uid, [], list(level_lines), level.id, run.date, context=context) + cr, uid, [], list(level_lines), level.id, run.date, context=context) if policy_generated_ids: report += _("Policy \"%s\" has generated %d Credit Control Lines.\n") % \ @@ -132,14 +132,14 @@ class CreditControlRun(Model): 'manual_ids': [(6, 0, manually_managed_lines)]} run.write(vals, context=context) - def generate_credit_lines(self, cursor, uid, run_id, context=None): + def generate_credit_lines(self, cr, uid, run_id, context=None): """Generate credit control lines Lock the ``credit_control_run`` Postgres table to avoid concurrent calls of this method. """ try: - cursor.execute('SELECT id FROM credit_control_run' + cr.execute('SELECT id FROM credit_control_run' ' LIMIT 1 FOR UPDATE NOWAIT' ) except Exception, exc: # in case of exception openerp will do a rollback for us and free the lock @@ -148,6 +148,6 @@ class CreditControlRun(Model): _('A credit control run is already running' ' in background, please try later.'), str(exc)) - self._generate_credit_lines(cursor, uid, run_id, context) + self._generate_credit_lines(cr, uid, run_id, context) return True diff --git a/account_credit_control/wizard/credit_control_communication.py b/account_credit_control/wizard/credit_control_communication.py index bad2d7d62..35bb65836 100644 --- a/account_credit_control/wizard/credit_control_communication.py +++ b/account_credit_control/wizard/credit_control_communication.py @@ -51,15 +51,15 @@ class CreditCommunication(TransientModel): cr, uid, 'credit.control.policy', context=c), 'user_id': lambda s, cr, uid, c: uid} - def get_address(self, cursor, uid, com_id, context=None): + def get_address(self, cr, uid, com_id, context=None): """Return a valid address for customer""" assert not (isinstance(com_id, list) and len(com_id) > 1), \ "com_id: only one id expected" if isinstance(com_id, list): com_id = com_id[0] - form = self.browse(cursor, uid, com_id, context=context) + form = self.browse(cr, uid, com_id, context=context) part_obj = self.pool.get('res.partner') - adds = part_obj.address_get(cursor, uid, [form.partner_id.id], + adds = part_obj.address_get(cr, uid, [form.partner_id.id], adr_pref=['invoice', 'default']) add = adds.get('invoice', adds.get('default')) @@ -67,15 +67,15 @@ class CreditCommunication(TransientModel): raise except_osv(_('No address for partner %s') % (form.partner_id.name), _('Please set one')) add_obj = self.pool.get('res.partner.address') - return add_obj.browse(cursor, uid, add, context=context) + return add_obj.browse(cr, uid, add, context=context) - def get_mail(self, cursor, uid, com_id, context=None): + def get_mail(self, cr, uid, com_id, context=None): """Return a valid email for customer""" context = context or {} if isinstance(com_id, list): com_id = com_id[0] - form = self.browse(cursor, uid, com_id, context=context) + form = self.browse(cr, uid, com_id, context=context) email = form.get_address().email if not email: raise except_osv(_('No invoicing or default email for partner %s') % @@ -83,19 +83,19 @@ class CreditCommunication(TransientModel): _('Please set one')) return email - def _get_credit_lines(self, cursor, uid, line_ids, partner_id, level_id, context=None): + def _get_credit_lines(self, cr, uid, line_ids, partner_id, level_id, context=None): """Return credit lines related to a partner and a policy level""" cr_line_obj = self.pool.get('credit.control.line') - cr_l_ids = cr_line_obj.search(cursor, + cr_l_ids = cr_line_obj.search(cr, uid, [('id', 'in', line_ids), ('partner_id', '=', partner_id), ('policy_level_id', '=', level_id)], context=context) - #return cr_line_obj.browse(cursor, uid, cr_l_ids, context=context) + #return cr_line_obj.browse(cr, uid, cr_l_ids, context=context) return cr_l_ids - def _generate_comm_from_credit_line_ids(self, cursor, uid, line_ids, context=None): + def _generate_comm_from_credit_line_ids(self, cr, uid, line_ids, context=None): if not line_ids: return [] comms = [] @@ -105,31 +105,31 @@ class CreditCommunication(TransientModel): " WHERE credit_control_line.id in %s" " ORDER by credit_control_policy_level.level") - cursor.execute(sql, (tuple(line_ids),)) - res = cursor.dictfetchall() + cr.execute(sql, (tuple(line_ids),)) + res = cr.dictfetchall() for level_assoc in res: data = {} data['credit_control_line_ids'] = \ - [(6, 0, self._get_credit_lines(cursor, uid, line_ids, + [(6, 0, self._get_credit_lines(cr, uid, line_ids, level_assoc['partner_id'], level_assoc['policy_level_id'], context=context))] data['partner_id'] = level_assoc['partner_id'] data['current_policy_level'] = level_assoc['policy_level_id'] - comm_id = self.create(cursor, uid, data, context=context) + comm_id = self.create(cr, uid, data, context=context) - comms.append(self.browse(cursor, uid, comm_id, context=context)) + comms.append(self.browse(cr, uid, comm_id, context=context)) return comms - def _generate_mails(self, cursor, uid, comms, context=None): + def _generate_mails(self, cr, uid, comms, context=None): """Generate mail message using template related to level""" cr_line_obj = self.pool.get('credit.control.line') mail_temp_obj = self.pool.get('email.template') mail_message_obj = self.pool.get('mail.message') mail_ids = [] for comm in comms: - # we want to use a local cursor in order to send the maximum + # we want to use a local cr in order to send the maximum # of email try: template = comm.current_policy_level.mail_template_id.id @@ -139,7 +139,7 @@ class CreditCommunication(TransientModel): # with this model, which is transient (only the owner of the # record can read it, and it is not persistent) # the template should be linked with the credit control line. - mvalues = mail_temp_obj.generate_email(cursor, uid, + mvalues = mail_temp_obj.generate_email(cr, uid, template, comm.id, context=context) @@ -150,40 +150,40 @@ class CreditCommunication(TransientModel): for val in essential_values: if not mvalues.get(val): raise Exception('Mail generation error with %s', val) - mail_id = mail_message_obj.create(cursor, uid, mvalues, context=context) + mail_id = mail_message_obj.create(cr, uid, mvalues, context=context) cl_ids = [cl.id for cl in comm.credit_control_line_ids] # we do not use local cusros else we have a lock # FIXME: so use a savepoint or find the cause of the lock # we are not supposed to rollback or commit the main transaction - cr_line_obj.write(cursor, uid, cl_ids, + cr_line_obj.write(cr, uid, cl_ids, {'mail_message_id': mail_id, 'state': 'sent'}, context=context) mail_ids.append(mail_id) except Exception, exc: logger.error(exc) - cursor.rollback() + cr.rollback() cl_ids = [cl.id for cl in comm.credit_control_line_ids] # we do not use local cusros else we have a lock - cr_line_obj.write(cursor, uid, cl_ids, + cr_line_obj.write(cr, uid, cl_ids, {'state': 'mail_error'}, context=context) finally: - cursor.commit() + cr.commit() return mail_ids - def _generate_report(self, cursor, uid, comms, context=None): + def _generate_report(self, cr, uid, comms, context=None): """Will generate a report by inserting mako template of related policy template""" service = netsvc.LocalService('report.credit_control_summary') ids = [x.id for x in comms] - result, format = service.create(cursor, uid, ids, {}, {}) + result, format = service.create(cr, uid, ids, {}, {}) return result - def _mark_credit_line_as_sent(self, cursor, uid, comms, context=None): + def _mark_credit_line_as_sent(self, cr, uid, comms, context=None): line_ids = [] for comm in comms: line_ids += [x.id for x in comm.credit_control_line_ids] l_obj = self.pool.get('credit.control.line') - l_obj.write(cursor, uid, line_ids, {'state': 'sent'}, context=context) + l_obj.write(cr, uid, line_ids, {'state': 'sent'}, context=context) return line_ids diff --git a/account_credit_control/wizard/credit_control_mailer.py b/account_credit_control/wizard/credit_control_mailer.py index f7be7357d..c30ef4bfc 100644 --- a/account_credit_control/wizard/credit_control_mailer.py +++ b/account_credit_control/wizard/credit_control_mailer.py @@ -31,14 +31,14 @@ class CreditControlMailer(TransientModel): _description = """Mass credit line mailer""" _rec_name = 'id' - def _get_line_ids(self, cursor, uid, context=None): + def _get_line_ids(self, cr, uid, context=None): if context is None: context = {} res = False if (context.get('active_model') == 'credit.control.line' and context.get('active_ids')): res = self._filter_line_ids( - cursor, uid, + cr, uid, False, context['active_ids'], context=context) @@ -56,7 +56,7 @@ class CreditControlMailer(TransientModel): 'line_ids': _get_line_ids, } - def _filter_line_ids(self, cursor, uid, mail_all, active_ids, context=None): + def _filter_line_ids(self, cr, uid, mail_all, active_ids, context=None): """filter lines to use in the wizard""" line_obj = self.pool.get('credit.control.line') if mail_all: @@ -66,24 +66,24 @@ class CreditControlMailer(TransientModel): domain = [('state', '=', 'to_be_sent'), ('id', 'in', active_ids), ('canal', '=', 'mail')] - return line_obj.search(cursor, uid, domain, context=context) + return line_obj.search(cr, uid, domain, context=context) - def mail_lines(self, cursor, uid, wiz_id, context=None): + def mail_lines(self, cr, uid, wiz_id, context=None): assert not (isinstance(wiz_id, list) and len(wiz_id) > 1), \ "wiz_id: only one id expected" comm_obj = self.pool.get('credit.control.communication') if isinstance(wiz_id, list): wiz_id = wiz_id[0] - form = self.browse(cursor, uid, wiz_id, context) + form = self.browse(cr, uid, wiz_id, context) if not form.line_ids and not form.mail_all: raise except_osv(_('Error'), _('No credit control lines selected.')) line_ids = [l.id for l in form.line_ids] filtered_ids = self._filter_line_ids( - cursor, uid, form.mail_all, line_ids, context) + cr, uid, form.mail_all, line_ids, context) comms = comm_obj._generate_comm_from_credit_line_ids( - cursor, uid, filtered_ids, context=context) - comm_obj._generate_mails(cursor, uid, comms, context=context) + cr, uid, filtered_ids, context=context) + comm_obj._generate_mails(cr, uid, comms, context=context) return {} diff --git a/account_credit_control/wizard/credit_control_marker.py b/account_credit_control/wizard/credit_control_marker.py index 31ee3f08c..a4037b986 100644 --- a/account_credit_control/wizard/credit_control_marker.py +++ b/account_credit_control/wizard/credit_control_marker.py @@ -29,14 +29,14 @@ class CreditControlMarker(TransientModel): _name = 'credit.control.marker' _description = 'Mass marker' - def _get_line_ids(self, cursor, uid, context=None): + def _get_line_ids(self, cr, uid, context=None): if context is None: context = {} res = False if (context.get('active_model') == 'credit.control.line' and context.get('active_ids')): res = self._filter_line_ids( - cursor, uid, + cr, uid, False, context['active_ids'], context=context) @@ -59,43 +59,43 @@ class CreditControlMarker(TransientModel): 'line_ids': _get_line_ids, } - def _filter_line_ids(self, cursor, uid, mark_all, active_ids, context=None): + def _filter_line_ids(self, cr, uid, mark_all, active_ids, context=None): """get line to be marked filter done lines""" line_obj = self.pool.get('credit.control.line') if mark_all: domain = [('state', '=', 'draft')] else: domain = [('state', '!=', 'sent'), ('id', 'in', active_ids)] - return line_obj.search(cursor, uid, domain, context=context) + return line_obj.search(cr, uid, domain, context=context) - def _mark_lines(self, cursor, uid, filtered_ids, state, context=None): + def _mark_lines(self, cr, uid, filtered_ids, state, context=None): """write hook""" line_obj = self.pool.get('credit.control.line') if not state: raise ValueError(_('state can not be empty')) - line_obj.write(cursor, uid, filtered_ids, {'state': state}, context=context) + line_obj.write(cr, uid, filtered_ids, {'state': state}, context=context) return filtered_ids - def mark_lines(self, cursor, uid, wiz_id, context=None): + def mark_lines(self, cr, uid, wiz_id, context=None): """Write state of selected credit lines to the one in entry done credit line will be ignored""" assert not (isinstance(wiz_id, list) and len(wiz_id) > 1), \ "wiz_id: only one id expected" if isinstance(wiz_id, list): wiz_id = wiz_id[0] - form = self.browse(cursor, uid, wiz_id, context) + form = self.browse(cr, uid, wiz_id, context) if not form.line_ids and not form.mark_all: raise except_osv(_('Error'), _('No credit control lines selected.')) line_ids = [l.id for l in form.line_ids] - filtered_ids = self._filter_line_ids(cursor, uid, form.mark_all, line_ids, context) + filtered_ids = self._filter_line_ids(cr, uid, form.mark_all, line_ids, context) if not filtered_ids: raise except_osv(_('Information'), _('No lines will be changed. All the selected lines are already done.')) - self._mark_lines(cursor, uid, filtered_ids, form.name, context) + self._mark_lines(cr, uid, filtered_ids, form.name, context) return {'domain': unicode([('id', 'in', filtered_ids)]), 'name': _('%s marked line') % (form.name,), diff --git a/account_credit_control/wizard/credit_control_printer.py b/account_credit_control/wizard/credit_control_printer.py index de746bae5..4a5336d93 100644 --- a/account_credit_control/wizard/credit_control_printer.py +++ b/account_credit_control/wizard/credit_control_printer.py @@ -31,7 +31,7 @@ class CreditControlPrinter(TransientModel): _rec_name = 'id' _description = 'Mass printer' - def _get_line_ids(self, cursor, uid, context=None): + def _get_line_ids(self, cr, uid, context=None): if context is None: context = {} res = False @@ -56,7 +56,7 @@ class CreditControlPrinter(TransientModel): 'line_ids': _get_line_ids, } - def _filter_line_ids(self, cursor, uid, print_all, active_ids, context=None): + def _filter_line_ids(self, cr, uid, print_all, active_ids, context=None): """filter lines to use in the wizard""" line_obj = self.pool.get('credit.control.line') if print_all: @@ -66,15 +66,15 @@ class CreditControlPrinter(TransientModel): domain = [('state', '=', 'to_be_sent'), ('id', 'in', active_ids), ('canal', '=', 'manual')] - return line_obj.search(cursor, uid, domain, context=context) + return line_obj.search(cr, uid, domain, context=context) - def print_lines(self, cursor, uid, wiz_id, context=None): + def print_lines(self, cr, uid, wiz_id, context=None): assert not (isinstance(wiz_id, list) and len(wiz_id) > 1), \ "wiz_id: only one id expected" comm_obj = self.pool.get('credit.control.communication') if isinstance(wiz_id, list): wiz_id = wiz_id[0] - form = self.browse(cursor, uid, wiz_id, context) + form = self.browse(cr, uid, wiz_id, context) if not form.line_ids and not form.print_all: raise except_osv(_('Error'), _('No credit control lines selected.')) @@ -82,18 +82,18 @@ class CreditControlPrinter(TransientModel): line_ids = [l.id for l in form.line_ids] if form.print_all: filtered_ids = self._filter_line_ids( - cursor, uid, form.print_all, line_ids, context) + cr, uid, form.print_all, line_ids, context) else: filtered_ids = line_ids comms = comm_obj._generate_comm_from_credit_line_ids( - cursor, uid, filtered_ids, context=context) - report_file = comm_obj._generate_report(cursor, uid, comms, context=context) + cr, uid, filtered_ids, context=context) + report_file = comm_obj._generate_report(cr, uid, comms, context=context) form.write({'report_file': base64.b64encode(report_file), 'state': 'done'}) if form.mark_as_sent: - filtered_ids = self._filter_line_ids(cursor, uid, False, line_ids, context) - comm_obj._mark_credit_line_as_sent(cursor, uid, comms, context=context) + filtered_ids = self._filter_line_ids(cr, uid, False, line_ids, context) + comm_obj._mark_credit_line_as_sent(cr, uid, comms, context=context) return False # do not close the window, we need it to download the report