account followup modif now it display summary

bzr revid: mra@tinyerp.com-20090129104106-ahuxg89a58x6xsst
This commit is contained in:
mra (Open ERP) 2009-01-29 16:11:06 +05:30
parent 8c2ddf57f3
commit 5a8a6cede2
2 changed files with 95 additions and 75 deletions

View File

@ -80,7 +80,7 @@ class report_rappel(report_sxw.rml_parse):
text = i.followup_line_id.description text = i.followup_line_id.description
a[delay] = text a[delay] = text
partner_delay.append(delay) partner_delay.append(delay)
text = a[max(partner_delay)] or '' text = partner_delay and a[max(partner_delay)] or ''
if text: if text:
text = text % {'partner_name':partner.name} text = text % {'partner_name':partner.name}
return text return text

View File

@ -29,6 +29,15 @@ import tools
from osv import fields, osv from osv import fields, osv
from tools.translate import _ from tools.translate import _
_email_summary_form = """<?xml version="1.0"?>
<form string="Summary">
<field name="summary" height="300" width="800"/>
</form>"""
_email_summary_fields = {
'summary': {'string': 'Summary', 'type': 'text', 'required': False, 'readonly': True},
}
_followup_wizard_screen1_form = """<?xml version="1.0"?> _followup_wizard_screen1_form = """<?xml version="1.0"?>
<form string="Follow-up and Date Selection"> <form string="Follow-up and Date Selection">
<field name="followup_id"/> <field name="followup_id"/>
@ -109,8 +118,6 @@ Thanks,
class followup_all_print(wizard.interface): class followup_all_print(wizard.interface):
def _update_partners(self, cr, uid, data, context): def _update_partners(self, cr, uid, data, context):
to_update = data['form']['to_update'] to_update = data['form']['to_update']
if data['form']['email_conf']:
self._sendmail(cr, uid, data, context)
for id in to_update.keys(): for id in to_update.keys():
cr.execute( cr.execute(
"UPDATE account_move_line "\ "UPDATE account_move_line "\
@ -121,78 +128,83 @@ class followup_all_print(wizard.interface):
return {} return {}
def _sendmail(self ,cr, uid, data, context): def _sendmail(self ,cr, uid, data, context):
mail_notsent = '' if data['form']['email_conf']:
count = 0 mail_notsent = ''
pool = pooler.get_pool(cr.dbname) msg_sent = ''
data_user = pool.get('res.users').browse(cr,uid,uid) msg_unsent = ''
line_obj = pool.get('account_followup.stat') count = 0
move_lines = line_obj.browse(cr,uid,data['form']['partner_ids'][0][2]) pool = pooler.get_pool(cr.dbname)
partners = [] data_user = pool.get('res.users').browse(cr,uid,uid)
dict_lines = {} line_obj = pool.get('account_followup.stat')
for line in move_lines: move_lines = line_obj.browse(cr,uid,data['form']['partner_ids'][0][2])
partners.append(line.name) partners = []
dict_lines[line.name.id] =line dict_lines = {}
for partner in partners: for line in move_lines:
ids_lines = pool.get('account.move.line').search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable'])]) partners.append(line.name)
data_lines = pool.get('account.move.line').browse(cr,uid,ids_lines) dict_lines[line.name.id] =line
followup_data = dict_lines[partner.id] for partner in partners:
dest = False ids_lines = pool.get('account.move.line').search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable'])])
if partner.address: data_lines = pool.get('account.move.line').browse(cr,uid,ids_lines)
for adr in partner.address: followup_data = dict_lines[partner.id]
if adr.type=='contact': dest = False
if adr.email: if partner.address:
dest = [adr.email] for adr in partner.address:
if (not dest) and adr.type=='default': if adr.type=='contact':
if adr.email: if adr.email:
dest = [adr.email] dest = [adr.email]
src = tools.config.options['smtp_user'] if (not dest) and adr.type=='default':
body=data['form']['email_body'] if adr.email:
total_amt = followup_data.debit - followup_data.credit dest = [adr.email]
move_line = '' src = tools.config.options['smtp_user']
subtotal_due = 0.0 body=data['form']['email_body']
subtotal_paid = 0.0 total_amt = followup_data.debit - followup_data.credit
subtotal_maturity = 0.0 move_line = ''
balance = 0.0 subtotal_due = 0.0
l = '--------------------------------------------------------------------------------------------------------------------------' subtotal_paid = 0.0
head = l+ '\n' + 'Date'.rjust(10) + '\t' + 'Description'.rjust(10) + '\t' + 'Ref'.rjust(10) + '\t' + 'Maturity date'.rjust(10) + '\t' + 'Due'.rjust(10) + '\t' + 'Paid'.rjust(10) + '\t' + 'Maturity'.rjust(10) + '\t' + 'Litigation'.rjust(10) + '\n' + l subtotal_maturity = 0.0
for i in data_lines: balance = 0.0
maturity = '' l = '--------------------------------------------------------------------------------------------------------------------------'
if i.date_maturity < time.strftime('%Y-%m-%d') and (i.debit - i.credit): head = l+ '\n' + 'Date'.rjust(10) + '\t' + 'Description'.rjust(10) + '\t' + 'Ref'.rjust(10) + '\t' + 'Maturity date'.rjust(10) + '\t' + 'Due'.rjust(10) + '\t' + 'Paid'.rjust(10) + '\t' + 'Maturity'.rjust(10) + '\t' + 'Litigation'.rjust(10) + '\n' + l
maturity = i.debit - i.credit for i in data_lines:
subtotal_due = subtotal_due + i.debit maturity = ''
subtotal_paid = subtotal_paid + i.credit if i.date_maturity < time.strftime('%Y-%m-%d') and (i.debit - i.credit):
subtotal_maturity = subtotal_maturity + int(maturity) maturity = i.debit - i.credit
balance = balance + (i.debit - i.credit) subtotal_due = subtotal_due + i.debit
move_line = move_line + (i.date).rjust(10) + '\t'+ (i.name).rjust(10) + '\t'+ (i.ref or '').rjust(10) + '\t' + (i.date_maturity or '').rjust(10) + '\t' + str(i.debit).rjust(10) + '\t' + str(i.credit).rjust(10) + '\t' + str(maturity).rjust(10) + '\t' + str(i.blocked).rjust(10) + '\n' subtotal_paid = subtotal_paid + i.credit
move_line = move_line + l + '\n'+ '\t\t\t' + 'Sub total'.rjust(35) + '\t' + (str(subtotal_due) or '').rjust(10) + '\t' + (str(subtotal_paid) or '').rjust(10) + '\t' + (str(subtotal_maturity) or '').rjust(10)+ '\n' subtotal_maturity = subtotal_maturity + int(maturity)
move_line = move_line + '\t\t\t' + 'Balance'.rjust(33) + '\t' + str(balance).rjust(10) + '\n' + l balance = balance + (i.debit - i.credit)
val = { move_line = move_line + (i.date).rjust(10) + '\t'+ (i.name).rjust(10) + '\t'+ (i.ref or '').rjust(10) + '\t' + (i.date_maturity or '').rjust(10) + '\t' + str(i.debit).rjust(10) + '\t' + str(i.credit).rjust(10) + '\t' + str(maturity).rjust(10) + '\t' + str(i.blocked).rjust(10) + '\n'
'partner_name':partner.name, move_line = move_line + l + '\n'+ '\t\t\t' + 'Sub total'.rjust(35) + '\t' + (str(subtotal_due) or '').rjust(10) + '\t' + (str(subtotal_paid) or '').rjust(10) + '\t' + (str(subtotal_maturity) or '').rjust(10)+ '\n'
'followup_amount':total_amt, move_line = move_line + '\t\t\t' + 'Balance'.rjust(33) + '\t' + str(balance).rjust(10) + '\n' + l
'user_signature':data_user.name, val = {
'company_name':data_user.company_id.name, 'partner_name':partner.name,
'company_currency':data_user.company_id.currency_id.name, 'followup_amount':total_amt,
'line':move_line, 'user_signature':data_user.name,
'heading': head, 'company_name':data_user.company_id.name,
'date':time.strftime('%Y-%m-%d'), 'company_currency':data_user.company_id.currency_id.name,
} 'line':move_line,
body = body%val 'heading': head,
sub = str(data['form']['email_subject']) 'date':time.strftime('%Y-%m-%d'),
msg = '' }
if dest: body = body%val
tools.email_send(src,dest,sub,body) sub = str(data['form']['email_subject'])
msg = ''
if dest:
tools.email_send(src,dest,sub,body)
msg_sent += partner.name + '\n'
else:
msg += partner.name + '\n'
msg_unsent += msg
if not msg_unsent:
summary = _("All emails have been successfully sent to Partners:.\n\n") + msg_sent
else: else:
msg += partner.name + '\n' msg_unsent = _("Mail not sent to following Partners, Email not available !\n\n") + msg_unsent
msg_sent = msg_sent and _("\n\nMail sent to following Partners successfully, !\n\n") + msg_sent
if not msg: line = '=========================================================================='
msg = _("All emails have been successfully sent.") summary = msg_unsent + line + msg_sent
else: return {'summary' : summary}
msg = _("Mail not sent to following Partners, Email not available !\n\n") + msg else:
warning = { return {'summary' : '\n\n\nMain not sent to any partner if you want to sent it please tick send email confirmation on wizard'}
'title': _('Email Sending Report'),
'message': msg,
}
return {'warning' : warning}
def _get_partners(self, cr, uid, data, context): def _get_partners(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname) pool = pooler.get_pool(cr.dbname)
@ -281,7 +293,15 @@ class followup_all_print(wizard.interface):
'actions': [_update_partners], 'actions': [_update_partners],
'result': {'type': 'print', 'result': {'type': 'print',
'report':'account_followup.followup.print', 'report':'account_followup.followup.print',
'state':'end'}, 'state':'summary'},
},
'summary': {
'actions': [_sendmail],
'result': {'type': 'form',
'arch': _email_summary_form,
'fields': _email_summary_fields,
'state':[('end','Ok')]
},
}, },
} }