From 5ef98ad35e29f10a980f1e3dc3790eba708bd61c Mon Sep 17 00:00:00 2001 From: Nicolas Bessi Date: Thu, 22 May 2014 15:12:50 +0200 Subject: [PATCH] [REFACTOR] printer filter to be more polite and improve the way to get ids --- .../wizard/credit_control_printer.py | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/account_credit_control/wizard/credit_control_printer.py b/account_credit_control/wizard/credit_control_printer.py index 3d67ec66b..028f18e1c 100644 --- a/account_credit_control/wizard/credit_control_printer.py +++ b/account_credit_control/wizard/credit_control_printer.py @@ -23,6 +23,7 @@ import base64 from openerp.osv import orm, fields from openerp.tools.translate import _ + class CreditControlPrinter(orm.TransientModel): """Print lines""" @@ -34,9 +35,9 @@ class CreditControlPrinter(orm.TransientModel): if context is None: context = {} res = False - if (context.get('active_model') == 'credit.control.line' and - context.get('active_ids')): - res = context['active_ids'] + if context.get('active_model') != 'credit.control.line': + return res + res = context.get('active_ids', False) return res _columns = { @@ -63,6 +64,12 @@ class CreditControlPrinter(orm.TransientModel): ('channel', '=', 'letter')] return line_obj.search(cr, uid, domain, context=context) + def _credit_line_predicate(self, cr, uid, line_record, context=None): + return True + + def _get_line_ids(self, cr, uid, lines, predicate, context=None): + return [l.id for l in lines if predicate(cr, uid, l, context)] + 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" @@ -72,9 +79,15 @@ class CreditControlPrinter(orm.TransientModel): form = self.browse(cr, uid, wiz_id, context) if not form.line_ids and not form.print_all: - raise orm.except_orm(_('Error'), _('No credit control lines selected.')) + raise orm.except_orm(_('Error'), + _('No credit control lines selected.')) + + line_ids = self._get_line_ids(cr, + uid, + form.line_ids, + self._credit_line_predicate, + context=context) - line_ids = [l.id for l in form.line_ids] comms = comm_obj._generate_comm_from_credit_line_ids(cr, uid, line_ids, context=context) report_file = comm_obj._generate_report(cr, uid, comms, context=context)