From 1280cf7e1e89dbb8f6e58920629e8f281559cfd5 Mon Sep 17 00:00:00 2001 From: "Guewen Baconnier @ Camptocamp" Date: Mon, 29 Oct 2012 14:38:25 +0100 Subject: [PATCH] [IMP] review of mailer / printer / marker wizards (lp:c2c-addons/6.1 rev 89.1.39) --- account_credit_control/line.py | 2 +- .../wizard/credit_control_mailer.py | 50 +++++++++---- .../wizard/credit_control_mailer_view.xml | 14 ++-- .../wizard/credit_control_marker.py | 65 +++++++++++------ .../wizard/credit_control_marker_view.xml | 6 +- .../wizard/credit_control_printer.py | 73 ++++++++++++------- .../wizard/credit_control_printer_view.xml | 17 +++-- 7 files changed, 145 insertions(+), 82 deletions(-) diff --git a/account_credit_control/line.py b/account_credit_control/line.py index 719d9a4eb..41129d010 100644 --- a/account_credit_control/line.py +++ b/account_credit_control/line.py @@ -60,7 +60,7 @@ class CreditControlLine(Model): 'State', required=True, readonly=True), 'canal': fields.selection([('manual', 'Manual'), - ('mail', 'Mail')], + ('mail', 'E-Mail')], 'Canal', required=True, readonly=True, states={'draft': [('readonly', False)]}), diff --git a/account_credit_control/wizard/credit_control_mailer.py b/account_credit_control/wizard/credit_control_mailer.py index 652010c2f..f7be7357d 100644 --- a/account_credit_control/wizard/credit_control_mailer.py +++ b/account_credit_control/wizard/credit_control_mailer.py @@ -18,6 +18,7 @@ # along with this program. If not, see . # ############################################################################## + from openerp.osv.orm import TransientModel, fields from openerp.osv.osv import except_osv from openerp.tools.translate import _ @@ -30,12 +31,33 @@ class CreditControlMailer(TransientModel): _description = """Mass credit line mailer""" _rec_name = 'id' - _columns = {'mail_all': fields.boolean('Send an email for all "Ready To Send" lines.')} + def _get_line_ids(self, cursor, 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, + False, + context['active_ids'], + context=context) + return res + _columns = { + 'mail_all': fields.boolean('Send an e-mail for all "Ready To Send" lines of the "E-Mail" channel'), + 'line_ids': fields.many2many( + 'credit.control.line', + string='Credit Control Lines', + domain="[('state', '=', 'to_be_sent'), ('canal', '=', 'mail')]"), + } - def _get_lids(self, cursor, uid, mail_all, active_ids, context=None): - """get line to be marked filter done lines""" - # TODO DRY with printer + _defaults = { + 'line_ids': _get_line_ids, + } + + def _filter_line_ids(self, cursor, 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: domain = [('state', '=', 'to_be_sent'), @@ -46,26 +68,22 @@ class CreditControlMailer(TransientModel): ('canal', '=', 'mail')] return line_obj.search(cursor, uid, domain, context=context) - def mail_lines(self, cursor, 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 context is None: - context = {} if isinstance(wiz_id, list): wiz_id = wiz_id[0] - current = self.browse(cursor, uid, wiz_id, context) - lines_ids = context.get('active_ids') + form = self.browse(cursor, uid, wiz_id, context) - if not lines_ids and not current.mail_all: - raise except_osv(_('Error'), - _('No lines are selected. You may want to activate ' - '"Send an email for all "Ready To Send" lines."')) + if not form.line_ids and not form.mail_all: + raise except_osv(_('Error'), _('No credit control lines selected.')) - filtered_ids = self._get_lids(cursor, uid, current.mail_all, lines_ids, context) - comms = comm_obj._generate_comm_from_credit_line_ids(cursor, uid, filtered_ids, - context=context) + line_ids = [l.id for l in form.line_ids] + filtered_ids = self._filter_line_ids( + cursor, 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) return {} diff --git a/account_credit_control/wizard/credit_control_mailer_view.xml b/account_credit_control/wizard/credit_control_mailer_view.xml index 2210d1529..e673a2a46 100644 --- a/account_credit_control/wizard/credit_control_mailer_view.xml +++ b/account_credit_control/wizard/credit_control_mailer_view.xml @@ -6,21 +6,23 @@ credit.control.mailer form -
- + + +