[IMP] review of mailer / printer / marker wizards

(lp:c2c-addons/6.1  rev 89.1.39)
This commit is contained in:
Guewen Baconnier @ Camptocamp
2012-10-29 14:38:25 +01:00
parent f627e75d61
commit 1280cf7e1e
7 changed files with 145 additions and 82 deletions

View File

@@ -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)]}),

View File

@@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
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 {}

View File

@@ -6,21 +6,23 @@
<field name="model">credit.control.mailer</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form> <!-- editable="bottom" -->
<separator string="Mail selected lines. Sucessfuly mailed lines will be in state done. Related email will be linked to the line" colspan="4"/>
<form>
<separator string="Send e-mails for the selected lines" colspan="4"/>
<newline/>
<field name="mail_all" colspan="4"/>
<field name="line_ids" colspan="4" nolabel="1"
attrs="{'invisible': [('mail_all', '=', True)]}" />
<newline/>
<group colspan="4">
<button special="cancel" string="Cancel" icon='gtk-cancel'/>
<button name="mail_lines" string="Mail lines" type="object" icon="gtk-execute"/>
<button name="mail_lines" string="Send the e-mails" type="object" icon="gtk-execute"/>
</group>
</form>
</field>
</record>
<!-- for menu -->
<act_window name="Mail lines"
<act_window name="Send By E-mail"
res_model="credit.control.mailer"
src_model="credit.control.line"
view_mode="form"
@@ -30,13 +32,13 @@
<!-- for button -->
<record id="open_credit_line_mailer_wizard" model="ir.actions.act_window">
<field name="name">Mail lines</field>
<field name="name">Send By E-mail</field>
<field name="res_model">credit.control.mailer</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="credit_line_mailer_form"/>
<field name="target">new</field>
<field name="help">Mail all marked lines</field>
<field name="help">Send an email for the selected lines.</field>
</record>

View File

@@ -22,20 +22,44 @@ from openerp.osv.orm import TransientModel, fields
from openerp.osv.osv import except_osv
from openerp.tools.translate import _
class CreditControlMarker(TransientModel):
"""Change the state of lines in mass"""
_name = "credit.control.marker"
_description = """Mass marker"""
_columns = {'name': fields.selection([('to_be_sent', 'Ready To Send'),
('sent', 'Done')],
'Mark as', required=True),
_name = 'credit.control.marker'
_description = 'Mass marker'
'mark_all': fields.boolean('Change status of all draft 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
_defaults = {'name': 'to_be_sent'}
_columns = {
'name': fields.selection([('draft', 'Draft'),
('to_be_sent', 'Ready To Send'),
('sent', 'Done')],
'Mark as', required=True),
'mark_all': fields.boolean('Change the status of all draft lines'),
'line_ids': fields.many2many(
'credit.control.line',
string='Credit Control Lines',
domain="[('state', '!=', 'sent')]"),
}
def _get_lids(self, cursor, uid, mark_all, active_ids, context=None):
_defaults = {
'name': 'to_be_sent',
'line_ids': _get_line_ids,
}
def _filter_line_ids(self, cursor, 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:
@@ -57,27 +81,24 @@ class CreditControlMarker(TransientModel):
done credit line will be ignored"""
assert not (isinstance(wiz_id, list) and len(wiz_id) > 1), \
"wiz_id: only one id expected"
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.mark_all:
raise except_osv(_('Error'),
_('No lines are selected. You may want to activate '
'"Change status of all draft lines"'))
filtered_ids = self._get_lids(cursor, uid, current.mark_all, lines_ids, 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)
if not filtered_ids:
raise except_osv(_('Information'),
_('No lines will be changed. All the selected lines are already done'))
_('No lines will be changed. All the selected lines are already done.'))
# hook function a simple write should be enought
self._mark_lines(cursor, uid, filtered_ids, current.name, context)
self._mark_lines(cursor, uid, filtered_ids, form.name, context)
return {'domain': "[('id','in',%s)]" % (filtered_ids,),
'name': _('%s marked line') % (current.name,),
return {'domain': unicode([('id', 'in', filtered_ids)]),
'name': _('%s marked line') % (form.name,),
'view_type': 'form',
'view_mode': 'tree,form',
'view_id': False,

View File

@@ -6,11 +6,13 @@
<field name="model">credit.control.marker</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form> <!-- editable="bottom" -->
<separator string="This wizard will change the state of the selected draft lines. Done Lines will be ignored " colspan="4"/>
<form>
<separator string="Change the state of the selected lines." colspan="4"/>
<newline/>
<field name="name"/>
<field name="mark_all"/>
<field name="line_ids" colspan="4" nolabel="1"
attrs="{'invisible': [('mark_all', '=', True)]}" />
<newline/>
<group colspan="4">
<button special="cancel" string="Cancel" icon='gtk-cancel'/>

View File

@@ -25,24 +25,39 @@ from openerp.osv.osv import except_osv
from openerp.tools.translate import _
class CreditControlPrinter(TransientModel):
"""Change the state of lines in mass"""
"""Print lines"""
_name = "credit.control.printer"
_rec_name = 'id'
_description = """Mass printer"""
_columns = {'mark_as_sent': fields.boolean('Mark lines as sent',
help="Only manual lines will be marked."),
'print_all': fields.boolean('Print all "Ready To Send" lines'),
'report_file': fields.binary('Generated Report', readonly=True),
'state': fields.char('state', size=32)}
_description = 'Mass printer'
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 = context['active_ids']
return res
_columns = {
'mark_as_sent': fields.boolean('Mark manual lines as sent',
help="Only manual lines will be marked."),
'print_all': fields.boolean('Print all "Ready To Send" lines of the "Manual" channel'),
'report_file': fields.binary('Generated Report', readonly=True),
'state': fields.char('state', size=32),
'line_ids': fields.many2many(
'credit.control.line',
string='Credit Control Lines'),
}
_defaults = {
'mark_as_sent': True,
'line_ids': _get_line_ids,
}
def _get_lids(self, cursor, uid, print_all, active_ids, context=None):
"""get line to be marked filter done lines"""
# TODO Dry with mailer maybe in comm
def _filter_line_ids(self, cursor, 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:
domain = [('state', '=', 'to_be_sent'),
@@ -53,30 +68,32 @@ class CreditControlPrinter(TransientModel):
('canal', '=', 'manual')]
return line_obj.search(cursor, uid, domain, context=context)
def print_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')
if not lines_ids and not current.print_all:
raise except_osv(_('Error'),
_('No lines are selected. You may want to activate'
' "Print all "Ready To Send" lines."'))
if current.print_all:
filtered_ids = self._get_lids(cursor, uid, current.print_all, lines_ids, context)
form = self.browse(cursor, uid, wiz_id, context)
if not form.line_ids and not form.print_all:
raise except_osv(_('Error'), _('No credit control lines selected.'))
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)
else:
filtered_ids = lines_ids
comms = comm_obj._generate_comm_from_credit_line_ids(cursor, uid, filtered_ids,
context=context)
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)
current.write({'report_file': base64.b64encode(report_file), 'state': 'done'})
if current.mark_as_sent:
filtered_ids = self._get_lids(cursor, uid, False, lines_ids, 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)
return False
return False # do not close the window, we need it to download the report

View File

@@ -6,18 +6,21 @@
<field name="model">credit.control.printer</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form> <!-- editable="bottom" -->
<separator colspan="4" string="This wizard will print the selected manual lines. Mark lines, lines will pass lines to state done. Lines with canal email will not be passed to state done"/>
<form>
<separator colspan="4" string="Print the selected lines"/>
<newline/>
<field name="mark_as_sent"/>
<field name="print_all"/>
<field name="mark_as_sent" attrs="{'invisible': [('state', '=', 'done')]}"/>
<field name="print_all" attrs="{'invisible': [('state', '=', 'done')]}"/>
<newline/>
<field name="report_file" attrs="{'readonly': [('state', '!=', 'done')]}" colspan="4"/>
<field name="line_ids" colspan="4" nolabel="1"
attrs="{'invisible': ['|', ('print_all', '=', True), ('state', '=', 'done')]}" />
<field name="report_file" colspan="4" attrs="{'invisible': [('state', '!=', 'done')]}"/>
<field name="state" invisible="1" />
<newline/>
<group colspan="4">
<button special="cancel" string="Cancel" icon='gtk-cancel'/>
<button name="print_lines" string="Print Lines" type="object" icon="gtk-execute"/>
<button special="cancel" string="Cancel" icon='gtk-cancel' attrs="{'invisible': [('state', '==', 'done')]}"/>
<button name="print_lines" string="Print" type="object" icon="gtk-execute" attrs="{'invisible': [('state', '==', 'done')]}"/>
<button special="cancel" string="Close" icon='gtk-close' attrs="{'invisible': [('state', '!=', 'done')]}"/>
</group>
</form>
</field>