From cd34d1769c7981c39a343150b7ae9c1535b27dad Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 19 Oct 2012 10:07:37 +0200 Subject: [PATCH 01/38] [ADD] first add of different fields bzr revid: jco@openerp.com-20121019080737-u925e4snkyo7nhjz --- addons/account_followup/account_followup.py | 25 +++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index 60499603295..6e2b17cf51b 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -28,7 +28,7 @@ class followup(osv.osv): 'name': fields.char('Name', size=64, required=True), 'description': fields.text('Description'), 'followup_line': fields.one2many('account_followup.followup.line', 'followup_id', 'Follow-up'), - 'company_id': fields.many2one('res.company', 'Company', required=True), + 'company_id': fields.many2one('res.company', 'Company', required=True), } _defaults = { 'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'account_followup.followup', context=c), @@ -46,10 +46,14 @@ class followup_line(osv.osv): 'start': fields.selection([('days','Net Days'),('end_of_month','End of Month')], 'Type of Term', size=64, required=True), 'followup_id': fields.many2one('account_followup.followup', 'Follow Ups', required=True, ondelete="cascade"), 'description': fields.text('Printed Message', translate=True), + 'send_email':fields.boolean('Send email', help="When processing, it will send an email"), + 'send_letter':fields.boolean('Print email'), + 'phonecall':fields.boolean('Phone call'), } _defaults = { 'start': 'days', - + 'send_email': True, + 'send_letter': False, } def _check_description(self, cr, uid, ids, context=None): for line in self.browse(cr, uid, ids, context=context): @@ -71,6 +75,10 @@ class account_move_line(osv.osv): _columns = { 'followup_line_id': fields.many2one('account_followup.followup.line', 'Follow-up Level'), 'followup_date': fields.date('Latest Follow-up', select=True), + 'payment_commitment':fields.text('Commitment'), + 'payment_date':fields.date('Date'), + 'payment_note':fields.text('Payment note'), + 'payment_new_action':fields.text('New action'), } account_move_line() @@ -79,6 +87,7 @@ class res_company(osv.osv): _inherit = "res.company" _columns = { 'follow_up_msg': fields.text('Follow-up Message', translate=True), + } _defaults = { @@ -100,4 +109,16 @@ Thanks, res_company() +class res_partner(osv.osv): + _inherit = "res.partner" + _columns = { + 'payment_responsible_id':fields.many2one('res.partner', ondelete='set null'), + 'payment_followup_level_id':fields.many2one('account_followup.followup.line', 'Followup line'), + 'payment_note':fields.text('Payment note', help="Payment note"), + 'payment_new_action':fields.text('New action'), + #followup_date:fields.function(''), + #followup_level_id:fields.function(''), + } +res_partner() + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 793aea15e594c4a02471da3672253c799482da0d Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 19 Oct 2012 19:29:17 +0200 Subject: [PATCH 02/38] [IMP] Added some views already bzr revid: jco@openerp.com-20121019172917-j7i71abfnrllrqu3 --- addons/account_followup/__openerp__.py | 1 + addons/account_followup/account_followup.py | 46 +++++++++++++++++-- .../account_followup_view.xml | 9 ++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/addons/account_followup/__openerp__.py b/addons/account_followup/__openerp__.py index 87b04c18219..6a5e144d6e0 100644 --- a/addons/account_followup/__openerp__.py +++ b/addons/account_followup/__openerp__.py @@ -56,6 +56,7 @@ Note that if you want to check the follow-up level for a given partner/account e 'account_followup_demo.xml', # Defined by default 'account_followup_view.xml', 'account_followup_data.xml', + 'account_followup_customers.xml', ], 'demo': [], 'test': [ diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index 6e2b17cf51b..78919f29d1c 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -20,6 +20,7 @@ ############################################################################## from osv import fields, osv +from datetime import date class followup(osv.osv): _name = 'account_followup.followup' @@ -109,15 +110,54 @@ Thanks, res_company() + + class res_partner(osv.osv): + + + def _get_latest_followup_date(self, cr, uid, ids): + res = {} + for partner in self.browse(cr, uid, ids): + accountmovelines = self.pool.get('account.account_move_line').search(cr, uid, [('partner_id', '=', partner.id)]) + latest_date = 0 + for accountmoveline in accountmovelines: + if (latest_date < accountmoveline.followup_date): + latest_date = accountmoveline.followup_date + res[partner.id] = latest_date + return res + + def _test_latestfollowup(self, cr, uid, ids, name, args, context = None): + res = {} + for partner in self.browse(cr, uid, ids, context = context): + res[partner.id] = 5 + return res + + def _dummyfollowup(self, cr, uid, ids, context = None): + return {} + + + def _get_latest_followup_level_id(self, cr, uid, ids, context = None): + res = {} + for partner in self.browse(cr, uid, ids, context = context): + accountmovelines = self.pool.get('account.account_move_line').search(cr, uid, [('partner_id', '=', partner.id)]) + level_id = 0 + level_days = -1000 + for accountmoveline in accountmovelines: + if (level_days < accountmoveline.followup_id.delay): + level_days = accountmoveline.followup_id.delay + latest_date = accountmoveline.followup_id.followup_date + res[partner.id] = latest_date + _inherit = "res.partner" _columns = { 'payment_responsible_id':fields.many2one('res.partner', ondelete='set null'), 'payment_followup_level_id':fields.many2one('account_followup.followup.line', 'Followup line'), 'payment_note':fields.text('Payment note', help="Payment note"), - 'payment_new_action':fields.text('New action'), - #followup_date:fields.function(''), - #followup_level_id:fields.function(''), + 'payment_new_action':fields.text('New action'), #one2many? + 'aml_ids':fields.one2many('account.move.line', 'partner_id'), + + #'latest_followup_date':fields.function('_dummy_followup', type='integer', string="latest_followup_date"), + #'latest_followup_level_id':fields.function('_get_followup_level_id', type='one2many'), } res_partner() diff --git a/addons/account_followup/account_followup_view.xml b/addons/account_followup/account_followup_view.xml index b26458a73af..f15395d1c33 100644 --- a/addons/account_followup/account_followup_view.xml +++ b/addons/account_followup/account_followup_view.xml @@ -9,6 +9,7 @@ + @@ -22,6 +23,13 @@ + + + + + + + @@ -109,6 +117,7 @@ + From be481fca4237501d2f3081d10b7a9a2b01fa090e Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 19 Oct 2012 19:29:57 +0200 Subject: [PATCH 03/38] [ADD] Added some views already bzr revid: jco@openerp.com-20121019172957-vryq87b6rx6pqhcc --- .../account_followup_customers.xml | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 addons/account_followup/account_followup_customers.xml diff --git a/addons/account_followup/account_followup_customers.xml b/addons/account_followup/account_followup_customers.xml new file mode 100644 index 00000000000..fbf1c5731a2 --- /dev/null +++ b/addons/account_followup/account_followup_customers.xml @@ -0,0 +1,77 @@ + + + + + + + eee + res.partner + form + +
+ + + + + + + + + + + + + + + +
+ + + ddd + res.partner + tree + + + + + + + + + + + + + + + + + Customer Follow Up + + res.partner + tree + + + + + + + + form + + + + + + + tree + + + + + + + +
+
\ No newline at end of file From 4e6090187577d857f16342008a96cd03e80095ea Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 22 Oct 2012 10:59:42 +0200 Subject: [PATCH 04/38] [IMP] Work in progress bzr revid: jco@openerp.com-20121022085942-x35eno43oxkpql7s --- addons/account_followup/account_followup.py | 14 ++++---- .../account_followup_customers.xml | 35 ++++++++++--------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index 78919f29d1c..5fcc6892ea5 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -126,14 +126,13 @@ class res_partner(osv.osv): res[partner.id] = latest_date return res - def _test_latestfollowup(self, cr, uid, ids, name, args, context = None): + def _test_latestfollowup(self, cr, uid, ids, name, arg, context = None): res = {} for partner in self.browse(cr, uid, ids, context = context): res[partner.id] = 5 return res - def _dummyfollowup(self, cr, uid, ids, context = None): - return {} + def _get_latest_followup_level_id(self, cr, uid, ids, context = None): @@ -150,14 +149,13 @@ class res_partner(osv.osv): _inherit = "res.partner" _columns = { - 'payment_responsible_id':fields.many2one('res.partner', ondelete='set null'), + #'payment_responsible_id':fields.many2one('res.partner', ondelete='set null'), 'payment_followup_level_id':fields.many2one('account_followup.followup.line', 'Followup line'), 'payment_note':fields.text('Payment note', help="Payment note"), 'payment_new_action':fields.text('New action'), #one2many? - 'aml_ids':fields.one2many('account.move.line', 'partner_id'), - - #'latest_followup_date':fields.function('_dummy_followup', type='integer', string="latest_followup_date"), - #'latest_followup_level_id':fields.function('_get_followup_level_id', type='one2many'), + 'accountmoveline_ids':fields.one2many('account.move.line', 'partner_id'), + 'latest_followup_date':fields.function(_test_latestfollowup, method=True, type='integer', string="latest followup date"), + #'latest_followup_level_id':fields.function(_get_followup_level_id, type='one2many'), } res_partner() diff --git a/addons/account_followup/account_followup_customers.xml b/addons/account_followup/account_followup_customers.xml index fbf1c5731a2..864b2520f5e 100644 --- a/addons/account_followup/account_followup_customers.xml +++ b/addons/account_followup/account_followup_customers.xml @@ -8,21 +8,23 @@ eee res.partner form +
- - + + + + - + - - - - - - - - + + + + + + + @@ -30,7 +32,8 @@ ddd res.partner - tree + + @@ -38,8 +41,7 @@ - - + @@ -50,8 +52,9 @@ Customer Follow Up res.partner - tree - + form + tree,form + [('customer', '=', True)] From 4e14df318069f4ba4c9a05f049a1baf95292fd25 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Tue, 23 Oct 2012 14:23:24 +0200 Subject: [PATCH 05/38] [IMP] First changes wizard and functional fields bzr revid: jco@openerp.com-20121023122324-xn3jr015b3ib7j47 --- addons/account_followup/account_followup.py | 68 +++++---- .../account_followup_customers.xml | 41 +++-- .../wizard/account_followup_print.py | 141 ++++++++++-------- .../wizard/account_followup_print_view.xml | 27 +--- 4 files changed, 152 insertions(+), 125 deletions(-) diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index 5fcc6892ea5..cee0feaf574 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -78,7 +78,7 @@ class account_move_line(osv.osv): 'followup_date': fields.date('Latest Follow-up', select=True), 'payment_commitment':fields.text('Commitment'), 'payment_date':fields.date('Date'), - 'payment_note':fields.text('Payment note'), + #'payment_note':fields.text('Payment note'), 'payment_new_action':fields.text('New action'), } @@ -115,48 +115,60 @@ res_company() class res_partner(osv.osv): - def _get_latest_followup_date(self, cr, uid, ids): + def _get_latest_followup_date(self, cr, uid, ids, name, arg, context=None): res = {} for partner in self.browse(cr, uid, ids): - accountmovelines = self.pool.get('account.account_move_line').search(cr, uid, [('partner_id', '=', partner.id)]) - latest_date = 0 - for accountmoveline in accountmovelines: - if (latest_date < accountmoveline.followup_date): - latest_date = accountmoveline.followup_date - res[partner.id] = latest_date - return res - def _test_latestfollowup(self, cr, uid, ids, name, arg, context = None): - res = {} - for partner in self.browse(cr, uid, ids, context = context): - res[partner.id] = 5 + + accountmovelines = partner.accountmoveline_ids + #max(x.followup_date for x in accountmovelines) + #latest_date = lambda a: date(2011, 1, 1) + #for accountmoveline in accountmovelines: + # if (accountmoveline.followup_date != False) and (latest_date < accountmoveline.followup_date): + # latest_date = accountmoveline.followup_date + #if accountmovelines: + amls2 = filter(lambda a: (a.state != 'draft') and (a.account_id.type is 'receivable') + and (a.debit > 0), accountmovelines) + res[partner.id] = max(x.followup_date for x in amls2) if len(amls2) else False + #else: + # res[partner.id] = False + + #res[partner.id] = max(x.followup_date for x in accountmovelines) if len(accountmovelines) else False return res - def _get_latest_followup_level_id(self, cr, uid, ids, context = None): + def _get_latest_followup_level_id(self, cr, uid, ids, name, arg, context=None): res = {} - for partner in self.browse(cr, uid, ids, context = context): - accountmovelines = self.pool.get('account.account_move_line').search(cr, uid, [('partner_id', '=', partner.id)]) + for partner in self.browse(cr, uid, ids): + amls = partner.accountmoveline_ids level_id = 0 - level_days = -1000 - for accountmoveline in accountmovelines: - if (level_days < accountmoveline.followup_id.delay): - level_days = accountmoveline.followup_id.delay - latest_date = accountmoveline.followup_id.followup_date - res[partner.id] = latest_date + level_days = -1000 #TO BE IMPROVED with boolean checking first time or by using MAX + latest_level = False + res[partner.id] = False + + for accountmoveline in amls: + if (accountmoveline.followup_line_id != False) and (level_days < accountmoveline.followup_line_id.delay) and (accountmoveline.state != "draft"): # and (accountmoveline.debit > 0): + level_days = accountmoveline.followup_line_id.delay + latest_level = accountmoveline.followup_line_id.id + res[partner.id] = latest_level + #res[partner.id] = max(x.followup_line_id.delay for x in amls) if len(amls) else False + return res _inherit = "res.partner" _columns = { - #'payment_responsible_id':fields.many2one('res.partner', ondelete='set null'), - 'payment_followup_level_id':fields.many2one('account_followup.followup.line', 'Followup line'), + 'payment_responsible_id':fields.many2one('res.users', ondelete='set null'), + #'payment_followup_level_id':fields.many2one('account_followup.followup.line', 'Followup line'), 'payment_note':fields.text('Payment note', help="Payment note"), - 'payment_new_action':fields.text('New action'), #one2many? - 'accountmoveline_ids':fields.one2many('account.move.line', 'partner_id'), - 'latest_followup_date':fields.function(_test_latestfollowup, method=True, type='integer', string="latest followup date"), - #'latest_followup_level_id':fields.function(_get_followup_level_id, type='one2many'), + 'payment_new_action':fields.text('New action'), #one2many/selection? + 'accountmoveline_ids':fields.one2many('account.move.line', 'partner_id'), + 'latest_followup_date':fields.function(_get_latest_followup_date, method=True, type='date', string="latest followup date"), + 'latest_followup_level_id':fields.function(_get_latest_followup_level_id, method=True, + type='many2one', relation='account_followup.followup.line', string="latest followup level"), } + + res_partner() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account_followup/account_followup_customers.xml b/addons/account_followup/account_followup_customers.xml index 864b2520f5e..5c659db2903 100644 --- a/addons/account_followup/account_followup_customers.xml +++ b/addons/account_followup/account_followup_customers.xml @@ -13,16 +13,32 @@
- + - - - + + + + + + + + + + + + + + + + + + - + + @@ -36,12 +52,14 @@ - - - - - - + + + + + + + + @@ -59,6 +77,7 @@ + form diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py index 5791bacbed0..e17b1669087 100644 --- a/addons/account_followup/wizard/account_followup_print.py +++ b/addons/account_followup/wizard/account_followup_print.py @@ -31,7 +31,7 @@ class account_followup_print(osv.osv_memory): _description = 'Print Follow-up & Send Mail to Customers' _columns = { 'date': fields.date('Follow-up Sending Date', required=True, help="This field allow you to select a forecast date to plan your follow-ups"), - 'followup_id': fields.many2one('account_followup.followup', 'Follow-Up', required=True), + 'followup_id': fields.many2one('account_followup.followup', 'Follow-Up', required=True, readonly = True), } def _get_followup(self, cr, uid, context=None): @@ -155,6 +155,7 @@ class account_followup_print_all(osv.osv_memory): data = self.browse(cr, uid, ids, context=context)[0] company_id = 'company_id' in context and context['company_id'] or data.company_id.id + cr.execute( "SELECT l.partner_id, l.followup_line_id,l.date_maturity, l.date, l.id "\ "FROM account_move_line AS l "\ @@ -193,8 +194,19 @@ class account_followup_print_all(osv.osv_memory): partner_list = [] to_update = {} for partner_id, followup_line_id, date_maturity,date, id in move_lines: + if not partner_id: continue + #part = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context) + #print "Respartner: " + part.send_letter + + #if not partns[0].send_letter: + # continue + + #if not partner_id.send_letter: + # continue + + if followup_line_id not in fups: continue stat_line_id = partner_id * 10000 + company_id @@ -207,6 +219,7 @@ class account_followup_print_all(osv.osv_memory): if stat_line_id not in partner_list: partner_list.append(stat_line_id) to_update[str(id)]= {'level': fups[followup_line_id][1], 'partner_id': stat_line_id} + return {'partner_ids': partner_list, 'to_update': to_update} def do_mail(self, cr, uid, ids, context=None): @@ -221,70 +234,71 @@ class account_followup_print_all(osv.osv_memory): partners = [stat_by_partner_line / 10000 for stat_by_partner_line in stat_by_partner_line_ids] model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all_msg')], context=context) resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] - if data.email_conf: + if True: #should not depend on this msg_sent = '' msg_unsent = '' data_user = user_obj.browse(cr, uid, uid, context=context) for partner in self.pool.get('res.partner').browse(cr, uid, partners, context=context): - ids_lines = move_obj.search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable']),('company_id','=',context.get('company_id', False))]) - data_lines = move_obj.browse(cr, uid, ids_lines, context=context) - total_amt = 0.0 - for line in data_lines: - total_amt += line.debit - line.credit - dest = False - if partner: - dest = [partner.email] - if not data.partner_lang: - body = data.email_body - else: - cxt = context.copy() - cxt['lang'] = partner.lang - body = user_obj.browse(cr, uid, uid, context=cxt).company_id.follow_up_msg - move_line = '' - subtotal_due = 0.0 - subtotal_paid = 0.0 - subtotal_maturity = 0.0 - balance = 0.0 - l = '--------------------------------------------------------------------------------------------------------------------------' - head = l+ '\n' + 'Date'.rjust(10) + '\t' + 'Description'.rjust(10) + '\t' + 'Ref'.rjust(10) + '\t' + 'Due date'.rjust(10) + '\t' + 'Due'.rjust(10) + '\t' + 'Paid'.rjust(10) + '\t' + 'Maturity'.rjust(10) + '\t' + 'Litigation'.rjust(10) + '\n' + l - for i in data_lines: - maturity = 0.00 - if i.date_maturity < time.strftime('%Y-%m-%d') and (i.debit - i.credit): - maturity = i.debit - i.credit - subtotal_due = subtotal_due + i.debit - subtotal_paid = subtotal_paid + i.credit - subtotal_maturity = subtotal_maturity + int(maturity) - balance = balance + (i.debit - i.credit) - 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' - 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' - move_line = move_line + '\t\t\t' + 'Balance'.rjust(33) + '\t' + str(balance).rjust(10) + '\n' + l - val = { - 'partner_name':partner.name, - 'followup_amount':total_amt, - 'user_signature':data_user.name, - 'company_name':data_user.company_id.name, - 'company_currency':data_user.company_id.currency_id.name, - 'line':move_line, - 'heading': head, - 'date':time.strftime('%Y-%m-%d'), - } - body = body%val - sub = tools.ustr(data.email_subject) - msg = '' - if dest: - try: - vals = {'state': 'outgoing', - 'subject': sub, - 'body_html': '
%s
' % body, - 'email_to': dest, - 'email_from': data_user.email or tools.config.options['email_from']} - self.pool.get('mail.mail').create(cr, uid, vals, context=context) - msg_sent += partner.name + '\n' - except Exception, e: - raise osv.except_osv('Error !', e ) - else: - msg += partner.name + '\n' - msg_unsent += msg + if True: #partner.latest_followup_level_id.send_email: + ids_lines = move_obj.search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable']),('company_id','=',context.get('company_id', False))]) + data_lines = move_obj.browse(cr, uid, ids_lines, context=context) + total_amt = 0.0 + for line in data_lines: + total_amt += line.debit - line.credit + dest = False + if partner: + dest = [partner.email] + if not data.partner_lang: + body = data.email_body + else: + cxt = context.copy() + cxt['lang'] = partner.lang + body = user_obj.browse(cr, uid, uid, context=cxt).company_id.follow_up_msg + move_line = '' + subtotal_due = 0.0 + subtotal_paid = 0.0 + subtotal_maturity = 0.0 + balance = 0.0 + l = '--------------------------------------------------------------------------------------------------------------------------' + head = l+ '\n' + 'Date'.rjust(10) + '\t' + 'Description'.rjust(10) + '\t' + 'Ref'.rjust(10) + '\t' + 'Due date'.rjust(10) + '\t' + 'Due'.rjust(10) + '\t' + 'Paid'.rjust(10) + '\t' + 'Maturity'.rjust(10) + '\t' + 'Litigation'.rjust(10) + '\n' + l + for i in data_lines: + maturity = 0.00 + if i.date_maturity < time.strftime('%Y-%m-%d') and (i.debit - i.credit): + maturity = i.debit - i.credit + subtotal_due = subtotal_due + i.debit + subtotal_paid = subtotal_paid + i.credit + subtotal_maturity = subtotal_maturity + int(maturity) + balance = balance + (i.debit - i.credit) + 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' + 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' + move_line = move_line + '\t\t\t' + 'Balance'.rjust(33) + '\t' + str(balance).rjust(10) + '\n' + l + val = { + 'partner_name':partner.name, + 'followup_amount':total_amt, + 'user_signature':data_user.name, + 'company_name':data_user.company_id.name, + 'company_currency':data_user.company_id.currency_id.name, + 'line':move_line, + 'heading': head, + 'date':time.strftime('%Y-%m-%d'), + } + body = body%val + sub = tools.ustr(data.email_subject) + msg = '' + if dest: + try: + vals = {'state': 'outgoing', + 'subject': sub, + 'body_html': '
%s
' % body, + 'email_to': dest, + 'email_from': data_user.email or tools.config.options['email_from']} + self.pool.get('mail.mail').create(cr, uid, vals, context=context) + msg_sent += partner.name + '\n' + except Exception, e: + raise osv.except_osv('Error !', e ) + else: + msg += partner.name + '\n' + msg_unsent += msg if not msg_unsent: summary = _("All Emails have been successfully sent to Partners:.\n\n%s") % msg_sent else: @@ -312,8 +326,9 @@ class account_followup_print_all(osv.osv_memory): if context is None: context = {} data = self.read(cr, uid, ids, [], context=context)[0] - res = self._get_partners_followp(cr, uid, ids, context)['to_update'] + res = self._get_partners_followp(cr, uid, ids, context)['to_update'] #-> only to_update part to_update = res + data['followup_id'] = 'followup_id' in context and context['followup_id'] or False date = 'date' in context and context['date'] or data['date'] if not data['test_print']: @@ -326,6 +341,7 @@ class account_followup_print_all(osv.osv_memory): (to_update[id]['level'], date, int(id),)) data.update({'date': context['date']}) + print data datas = { 'ids': [], 'model': 'account_followup.followup', @@ -337,6 +353,7 @@ class account_followup_print_all(osv.osv_memory): 'datas': datas, } + account_followup_print_all() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account_followup/wizard/account_followup_print_view.xml b/addons/account_followup/wizard/account_followup_print_view.xml index fe77dbc053e..8fac644664c 100644 --- a/addons/account_followup/wizard/account_followup_print_view.xml +++ b/addons/account_followup/wizard/account_followup_print_view.xml @@ -71,33 +71,12 @@
- - - - - - - - - - - - - - - - +
From 5518ab757bd49d14cc8b2cc90526c3150e8c867a Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Wed, 24 Oct 2012 17:37:34 +0200 Subject: [PATCH 06/38] [IMP] Wizard extra button try + next level field bzr revid: jco@openerp.com-20121024153734-rda572kyd627yims --- addons/account_followup/account_followup.py | 50 ++++++++++++++++--- .../account_followup_customers.xml | 47 +++++++++++++---- .../wizard/account_followup_print.py | 28 ++++++++++- .../wizard/account_followup_print_view.xml | 6 +++ 4 files changed, 110 insertions(+), 21 deletions(-) diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index cee0feaf574..e3fc28b58ff 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -127,8 +127,7 @@ class res_partner(osv.osv): # if (accountmoveline.followup_date != False) and (latest_date < accountmoveline.followup_date): # latest_date = accountmoveline.followup_date #if accountmovelines: - amls2 = filter(lambda a: (a.state != 'draft') and (a.account_id.type is 'receivable') - and (a.debit > 0), accountmovelines) + amls2 = filter(lambda a: (a.state != 'draft') and (a.debit > 0), accountmovelines) res[partner.id] = max(x.followup_date for x in amls2) if len(amls2) else False #else: # res[partner.id] = False @@ -149,23 +148,58 @@ class res_partner(osv.osv): res[partner.id] = False for accountmoveline in amls: - if (accountmoveline.followup_line_id != False) and (level_days < accountmoveline.followup_line_id.delay) and (accountmoveline.state != "draft"): # and (accountmoveline.debit > 0): + if (accountmoveline.followup_line_id != False) and (level_days < accountmoveline.followup_line_id.delay): + # and (accountmoveline.debit > 0): (accountmoveline.state != "draft") and + #and (accountmoveline.reconcile_id == None) level_days = accountmoveline.followup_line_id.delay latest_level = accountmoveline.followup_line_id.id res[partner.id] = latest_level #res[partner.id] = max(x.followup_line_id.delay for x in amls) if len(amls) else False return res + def get_latest_followup_level(self): + amls = self.accountmoveline_ids + + + def _get_next_followup_level_id(self, cr, uid, ids, name, arg, context=None): + res = {} + for partner in self.browse(cr, uid, ids): + latest_id = self._get_latest_followup_level_id(cr, uid, [partner.id], name, arg, context)[partner.id] + latest = self.pool.get('account_followup.followup.line').browse(cr, uid, [latest_id], context)[0] + delay = False + newlevel = False + if latest: #if latest exists + newlevel = latest.id + old_delay = latest.delay + else: + old_delay = False + + for fl in self.pool.get('account_followup.followup.line').search(cr, uid, []): #('followup_id.company_id','=',latest.followup_id.company_id) + fl_obj = self.pool.get('account_followup.followup.line').browse(cr, uid, [fl])[0] + if not old_delay: + if not delay or fl_obj.delay < delay: + delay = fl_obj.delay + newlevel = fl_obj.id + else: + if (not delay and (fl_obj.delay > old_delay)) or ((fl_obj.delay < delay) and (fl_obj.delay > old_delay)): + delay = fl_obj.delay + newlevel = fl_obj.id + res[partner.id] = newlevel + #Now search one level higher + return res + _inherit = "res.partner" _columns = { - 'payment_responsible_id':fields.many2one('res.users', ondelete='set null'), + 'payment_responsible_id':fields.many2one('res.users', ondelete='set null', string='Responsible', help="Responsible"), #'payment_followup_level_id':fields.many2one('account_followup.followup.line', 'Followup line'), - 'payment_note':fields.text('Payment note', help="Payment note"), + 'payment_note':fields.text('Payment note', help="Payment note"), 'payment_new_action':fields.text('New action'), #one2many/selection? - 'accountmoveline_ids':fields.one2many('account.move.line', 'partner_id'), - 'latest_followup_date':fields.function(_get_latest_followup_date, method=True, type='date', string="latest followup date"), + 'accountmoveline_ids':fields.one2many('account.move.line', 'partner_id', domain=['&', ('debit', '>', 0.0), '&', ('reconcile_id', '=', False), '&', + ('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')]), + 'latest_followup_date':fields.function(_get_latest_followup_date, method=True, type='date', string="latest followup date", store=True), 'latest_followup_level_id':fields.function(_get_latest_followup_level_id, method=True, - type='many2one', relation='account_followup.followup.line', string="latest followup level"), + type='many2one', relation='account_followup.followup.line', string="latest followup level", store=True), + 'next_followup_level_id':fields.function(_get_next_followup_level_id, method=True, type='many2one', relation='account_followup.followup.line', string="next level"), } diff --git a/addons/account_followup/account_followup_customers.xml b/addons/account_followup/account_followup_customers.xml index 5c659db2903..d5a6e36112a 100644 --- a/addons/account_followup/account_followup_customers.xml +++ b/addons/account_followup/account_followup_customers.xml @@ -16,30 +16,37 @@ - + - - + + + + - - - + + + + + + + - + + @@ -48,23 +55,38 @@ ddd res.partner - + - + + + - + + + Search + res.partner + search + + + + + + + + + Customer Follow Up @@ -72,12 +94,15 @@ res.partner form tree,form - [('customer', '=', True)] + + + + form diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py index e17b1669087..605fe5b6347 100644 --- a/addons/account_followup/wizard/account_followup_print.py +++ b/addons/account_followup/wizard/account_followup_print.py @@ -188,7 +188,6 @@ class account_followup_print_all(osv.osv_memory): if result['start'] == 'end_of_month': fups[old][0].replace(day=1) old = result['id'] - fups[old] = (datetime.date(datetime.MAXYEAR, 12, 31), old) partner_list = [] @@ -239,7 +238,7 @@ class account_followup_print_all(osv.osv_memory): msg_unsent = '' data_user = user_obj.browse(cr, uid, uid, context=context) for partner in self.pool.get('res.partner').browse(cr, uid, partners, context=context): - if True: #partner.latest_followup_level_id.send_email: + if partner.next_followup_level_id.send_email: ids_lines = move_obj.search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable']),('company_id','=',context.get('company_id', False))]) data_lines = move_obj.browse(cr, uid, ids_lines, context=context) total_amt = 0.0 @@ -353,6 +352,31 @@ class account_followup_print_all(osv.osv_memory): 'datas': datas, } + def do_process(self, cr, uid, ids, context=None): + resu = self.do_mail(cr,uid,ids,context) + mod_obj = self.pool.get('ir.model.data') + move_obj = self.pool.get('account.move.line') + user_obj = self.pool.get('res.users') + if context is None: + context = {} + data = self.browse(cr, uid, ids, context=context)[0] + stat_by_partner_line_ids = [partner_id.id for partner_id in data.partner_ids] + partners = [stat_by_partner_line / 10000 for stat_by_partner_line in stat_by_partner_line_ids] + model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all_msg')], context=context) + resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] + print "start changeof new action..." + + partnersfilt = [] + partner_obj = self.pool.get('res.partner') + for partner in partner_obj.browse(cr, uid, partners, context): + if partner.next_followup_level_id.phonecall: + partnersfilt.append(partner.id) + print "Should have been changed" + print partner.name + partner_obj = self.pool.get('res.partner').write(cr, uid, partnersfilt, {'payment_new_action': "Take your phone and call him, please!!!"}) + resu2 = self.do_print(cr,uid,ids,context) + return resu2 + account_followup_print_all() diff --git a/addons/account_followup/wizard/account_followup_print_view.xml b/addons/account_followup/wizard/account_followup_print_view.xml index 8fac644664c..e8ea58aa2b3 100644 --- a/addons/account_followup/wizard/account_followup_print_view.xml +++ b/addons/account_followup/wizard/account_followup_print_view.xml @@ -100,5 +100,11 @@ form new + + + + + + From 60372263decd212845bc55711c3587f4249643e2 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Thu, 25 Oct 2012 10:08:22 +0200 Subject: [PATCH 07/38] [IMP] Changes dates bzr revid: jco@openerp.com-20121025080822-7pbbpwoveuqv3u64 --- addons/account_followup/account_followup.py | 5 ++-- .../account_followup_customers.xml | 30 ++++++++----------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index e3fc28b58ff..d0e9da38e52 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -79,7 +79,7 @@ class account_move_line(osv.osv): 'payment_commitment':fields.text('Commitment'), 'payment_date':fields.date('Date'), #'payment_note':fields.text('Payment note'), - 'payment_new_action':fields.text('New action'), + 'payment_next_action':fields.text('New action'), } account_move_line() @@ -193,7 +193,8 @@ class res_partner(osv.osv): 'payment_responsible_id':fields.many2one('res.users', ondelete='set null', string='Responsible', help="Responsible"), #'payment_followup_level_id':fields.many2one('account_followup.followup.line', 'Followup line'), 'payment_note':fields.text('Payment note', help="Payment note"), - 'payment_new_action':fields.text('New action'), #one2many/selection? + 'payment_next_action':fields.text('Next action', help="Write here the comments of your customer"), #Just a note + 'payment_next_action_date':fields.date('Next action date', help="Next date to take action"), # next action date 'accountmoveline_ids':fields.one2many('account.move.line', 'partner_id', domain=['&', ('debit', '>', 0.0), '&', ('reconcile_id', '=', False), '&', ('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')]), 'latest_followup_date':fields.function(_get_latest_followup_date, method=True, type='date', string="latest followup date", store=True), diff --git a/addons/account_followup/account_followup_customers.xml b/addons/account_followup/account_followup_customers.xml index d5a6e36112a..859170f1beb 100644 --- a/addons/account_followup/account_followup_customers.xml +++ b/addons/account_followup/account_followup_customers.xml @@ -37,16 +37,14 @@ - - + - - - + + @@ -59,16 +57,17 @@ - - - + + + - - + - - - + + + @@ -94,15 +93,12 @@ res.partner form tree,form - + [] - - - form From 43f0cb9b1f9887d9ac194a7725af88bf73c98857 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 25 Oct 2012 11:15:44 +0200 Subject: [PATCH 08/38] [WIP] account_followup: refactoring of whole followup process. bzr revid: qdp-launchpad@openerp.com-20121025091544-pbnjs4yg9vfnta2w --- .../account_followup_data.xml | 102 ++++- .../wizard/account_followup_print.py | 411 ++++++++++-------- 2 files changed, 318 insertions(+), 195 deletions(-) diff --git a/addons/account_followup/account_followup_data.xml b/addons/account_followup/account_followup_data.xml index 2a33e65b2c8..52e6180a887 100644 --- a/addons/account_followup/account_followup_data.xml +++ b/addons/account_followup/account_followup_data.xml @@ -1,19 +1,101 @@ - - - Date : %(date)s + + -Dear %(partner_name)s, + + + + ${object.user_id.email or ''} + ${object.company_id.name} Followup + ${object.email} + + + +TYPE HERE THE MAIL CONTENT YOU WANT +

Hello${object.partner_id.name and ' ' or ''}${object.partner_id.name or ''},

+ +

Here is your ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} from ${object.company_id.name}:

-Please find in attachment a reminder of all your unpaid invoices, for a total amount due of: +

+   REFERENCES
+   Order number: ${object.name}
+   Order total: ${object.amount_total} ${object.pricelist_id.currency_id.name}
+   Order date: ${object.date_order}
+ % if object.origin: +   Order reference: ${object.origin}
+ % endif + % if object.client_order_ref: +   Your reference: ${object.client_order_ref}
+ % endif +   Your contact: ${object.user_id.name} +

-%(followup_amount).2f %(company_currency)s +

+ You can view the ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} document, download it and pay online using the following link: +

+ View Order -Thanks, --- -%(user_signature)s -%(company_name)s
+ % if object.order_policy in ('prepaid','manual') and object.company_id.paypal_account and object.state not in ('draft', 'sent'): + <% + comp_name = quote(object.company_id.name) + order_name = quote(object.name) + paypal_account = quote(object.company_id.paypal_account) + order_amount = quote(str(object.amount_total)) + cur_name = quote(object.pricelist_id.currency_id.name) + paypal_url = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=%s&item_name=%s%%20Order%%20%s" \ + "&invoice=%s&amount=%s&currency_code=%s&button_subtype=services&no_note=1" \ + "&bn=OpenERP_Order_PayNow_%s" % \ + (paypal_account,comp_name,order_name,order_name,order_amount,cur_name,cur_name) + %> +
+

It is also possible to directly pay with Paypal:

+ + + + % endif + +
+

If you have any question, do not hesitate to contact us.

+

Thank you for choosing ${object.company_id.name or 'us'}!

+
+
+
+

+ ${object.company_id.name}

+
+
+ + % if object.company_id.street: + ${object.company_id.street}
+ % endif + % if object.company_id.street2: + ${object.company_id.street2}
+ % endif + % if object.company_id.city or object.company_id.zip: + ${object.company_id.zip} ${object.company_id.city}
+ % endif + % if object.company_id.country_id: + ${object.company_id.state_id and ('%s, ' % object.company_id.state_id.name) or ''} ${object.company_id.country_id.name or ''}
+ % endif +
+ % if object.company_id.phone: +
+ Phone:  ${object.company_id.phone} +
+ % endif + % if object.company_id.website: + + %endif +

+
+ + ]]>
diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py index 605fe5b6347..e3366af8041 100644 --- a/addons/account_followup/wizard/account_followup_print.py +++ b/addons/account_followup/wizard/account_followup_print.py @@ -26,49 +26,6 @@ import tools from osv import fields, osv from tools.translate import _ -class account_followup_print(osv.osv_memory): - _name = 'account.followup.print' - _description = 'Print Follow-up & Send Mail to Customers' - _columns = { - 'date': fields.date('Follow-up Sending Date', required=True, help="This field allow you to select a forecast date to plan your follow-ups"), - 'followup_id': fields.many2one('account_followup.followup', 'Follow-Up', required=True, readonly = True), - } - - def _get_followup(self, cr, uid, context=None): - if context is None: - context = {} - if context.get('active_model', 'ir.ui.menu') == 'account_followup.followup': - return context.get('active_id', False) - company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id - followp_id = self.pool.get('account_followup.followup').search(cr, uid, [('company_id', '=', company_id)], context=context) - return followp_id and followp_id[0] or False - - def do_continue(self, cr, uid, ids, context=None): - mod_obj = self.pool.get('ir.model.data') - - if context is None: - context = {} - data = self.browse(cr, uid, ids, context=context)[0] - model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all')], context=context) - resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] - context.update({'followup_id': data.followup_id.id, 'date': data.date, 'company_id': data.followup_id.company_id.id}) - return { - 'name': _('Select Partners'), - 'view_type': 'form', - 'context': context, - 'view_mode': 'tree,form', - 'res_model': 'account.followup.print.all', - 'views': [(resource_id,'form')], - 'type': 'ir.actions.act_window', - 'target': 'new', - } - - _defaults = { - 'date': lambda *a: time.strftime('%Y-%m-%d'), - 'followup_id': _get_followup, - } -account_followup_print() - class account_followup_stat_by_partner(osv.osv): _name = "account_followup.stat.by.partner" _description = "Follow-up Statistics by Partner" @@ -116,37 +73,109 @@ class account_followup_stat_by_partner(osv.osv): )""") account_followup_stat_by_partner() -class account_followup_print_all(osv.osv_memory): - _name = 'account.followup.print.all' +class account_followup_print(osv.osv_memory): + _name = 'account.followup.print' _description = 'Print Follow-up & Send Mail to Customers' _columns = { - 'partner_ids': fields.many2many('account_followup.stat.by.partner', 'partner_stat_rel', 'osv_memory_id', 'partner_id', 'Partners', required=True), - 'email_conf': fields.boolean('Send Email Confirmation'), - 'email_subject': fields.char('Email Subject', size=64), - 'partner_lang': fields.boolean('Send Email in Partner Language', help='Do not change message text, if you want to send email in partner language, or configure from company'), - 'email_body': fields.text('Email Body'), - 'summary': fields.text('Summary', required=True, readonly=True), - 'test_print': fields.boolean('Test Print', help='Check if you want to print follow-ups without changing follow-ups level.') + 'date': fields.date('Follow-up Sending Date', required=True, help="This field allow you to select a forecast date to plan your follow-ups"), + 'followup_id': fields.many2one('account_followup.followup', 'Follow-Up', required=True, readonly = True), } - def _get_summary(self, cr, uid, context=None): + + def _get_followup(self, cr, uid, context=None): if context is None: context = {} - return context.get('summary', '') + if context.get('active_model', 'ir.ui.menu') == 'account_followup.followup': + return context.get('active_id', False) + company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id + followp_id = self.pool.get('account_followup.followup').search(cr, uid, [('company_id', '=', company_id)], context=context) + return followp_id and followp_id[0] or False - def _get_partners(self, cr, uid, context=None): - return self._get_partners_followp(cr, uid, [], context=context)['partner_ids'] - - def _get_msg(self, cr, uid, context=None): - return self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.follow_up_msg +# def do_continue(self, cr, uid, ids, context=None): +# mod_obj = self.pool.get('ir.model.data') +# +# if context is None: +# context = {} +# data = self.browse(cr, uid, ids, context=context)[0] +# model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all')], context=context) +# resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] +# context.update({'followup_id': data.followup_id.id, 'date': data.date, 'company_id': data.followup_id.company_id.id}) +# return { +# 'name': _('Select Partners'), +# 'view_type': 'form', +# 'context': context, +# 'view_mode': 'tree,form', +# 'res_model': 'account.followup.print.all', +# 'views': [(resource_id,'form')], +# 'type': 'ir.actions.act_window', +# 'target': 'new', +# } _defaults = { - 'email_body': _get_msg, - 'email_subject': _('Invoices Reminder'), - 'partner_lang': True, - 'partner_ids': _get_partners, - 'summary': _get_summary, + 'date': lambda *a: time.strftime('%Y-%m-%d'), + 'followup_id': _get_followup, } + def process_partner(self, cr, uid, partner_id, context=None): + partner = self.pool.get('account_followup.stat.by.partner').browse(cr, uid, partner_id, context=context) + if partner.next_followup_level_id.phonecall: + self.do_partner_phonecall(cr, uid, partner_id, context) + if partner.next_followup_level_id.mail: + self.do_partner_mail() + if partner.next_followup_level_id.manual: + self.do_partner_manual() + + def do_update_followup_level(self, cr, uid, to_update, context=None): + #update the followupo level on account.move.line + for id in to_update.keys(): + if to_update[id]['partner_id'] in data['partner_ids']: + cr.execute( + "UPDATE account_move_line "\ + "SET followup_line_id=%s, followup_date=%s "\ + "WHERE id=%s", + (to_update[id]['level'], + date, int(id),)) + + def do_process(self, cr, uid, ids, context=None): + tmp = self._get_partners_followp(cr, uid, ids, context=context) + partner_list = tmp['partner_ids'] + to_update = tmp['to_update'] + self.do_update_followup_level(cr, uid, to_update, context=context) + for partner in partner_list: + process_partner(cr, uid, partner, context=context) +#account_followup_print() + + +#class account_followup_print_all(osv.osv_memory): +# _name = 'account.followup.print.all' +# _description = 'Print Follow-up & Send Mail to Customers' +# _columns = { +# 'partner_ids': fields.many2many('account_followup.stat.by.partner', 'partner_stat_rel', 'osv_memory_id', 'partner_id', 'Partners', required=True), +# 'email_conf': fields.boolean('Send Email Confirmation'), +# 'email_subject': fields.char('Email Subject', size=64), +# 'partner_lang': fields.boolean('Send Email in Partner Language', help='Do not change message text, if you want to send email in partner language, or configure from company'), +# 'email_body': fields.text('Email Body'), +# 'summary': fields.text('Summary', required=True, readonly=True), +# 'test_print': fields.boolean('Test Print', help='Check if you want to print follow-ups without changing follow-ups level.') +# } +# def _get_summary(self, cr, uid, context=None): +# if context is None: +# context = {} +# return context.get('summary', '') +# +# def _get_partners(self, cr, uid, context=None): +# return self._get_partners_followp(cr, uid, [], context=context)['partner_ids'] +# +# def _get_msg(self, cr, uid, context=None): +# return self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.follow_up_msg +# +# _defaults = { +# 'email_body': _get_msg, +# 'email_subject': _('Invoices Reminder'), +# 'partner_lang': True, +# 'partner_ids': _get_partners, +# 'summary': _get_summary, +# } + def _get_partners_followp(self, cr, uid, ids, context=None): data = {} if context is None: @@ -221,105 +250,112 @@ class account_followup_print_all(osv.osv_memory): return {'partner_ids': partner_list, 'to_update': to_update} - def do_mail(self, cr, uid, ids, context=None): - mod_obj = self.pool.get('ir.model.data') - move_obj = self.pool.get('account.move.line') - user_obj = self.pool.get('res.users') + def do_partner_mail(self, cr, uid, partner_ids, context=None): + #get the mail template to use + mail_template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_followup', 'email_template_account_followup', context=context) + #complete the mail body with partner information + #(to be discussed with fp) attach the report to the mail or include the move lines in the mail body + #send the mail (need to check the function name) - if context is None: - context = {} - data = self.browse(cr, uid, ids, context=context)[0] - stat_by_partner_line_ids = [partner_id.id for partner_id in data.partner_ids] - partners = [stat_by_partner_line / 10000 for stat_by_partner_line in stat_by_partner_line_ids] - model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all_msg')], context=context) - resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] - if True: #should not depend on this - msg_sent = '' - msg_unsent = '' - data_user = user_obj.browse(cr, uid, uid, context=context) - for partner in self.pool.get('res.partner').browse(cr, uid, partners, context=context): - if partner.next_followup_level_id.send_email: - ids_lines = move_obj.search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable']),('company_id','=',context.get('company_id', False))]) - data_lines = move_obj.browse(cr, uid, ids_lines, context=context) - total_amt = 0.0 - for line in data_lines: - total_amt += line.debit - line.credit - dest = False - if partner: - dest = [partner.email] - if not data.partner_lang: - body = data.email_body - else: - cxt = context.copy() - cxt['lang'] = partner.lang - body = user_obj.browse(cr, uid, uid, context=cxt).company_id.follow_up_msg - move_line = '' - subtotal_due = 0.0 - subtotal_paid = 0.0 - subtotal_maturity = 0.0 - balance = 0.0 - l = '--------------------------------------------------------------------------------------------------------------------------' - head = l+ '\n' + 'Date'.rjust(10) + '\t' + 'Description'.rjust(10) + '\t' + 'Ref'.rjust(10) + '\t' + 'Due date'.rjust(10) + '\t' + 'Due'.rjust(10) + '\t' + 'Paid'.rjust(10) + '\t' + 'Maturity'.rjust(10) + '\t' + 'Litigation'.rjust(10) + '\n' + l - for i in data_lines: - maturity = 0.00 - if i.date_maturity < time.strftime('%Y-%m-%d') and (i.debit - i.credit): - maturity = i.debit - i.credit - subtotal_due = subtotal_due + i.debit - subtotal_paid = subtotal_paid + i.credit - subtotal_maturity = subtotal_maturity + int(maturity) - balance = balance + (i.debit - i.credit) - 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' - 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' - move_line = move_line + '\t\t\t' + 'Balance'.rjust(33) + '\t' + str(balance).rjust(10) + '\n' + l - val = { - 'partner_name':partner.name, - 'followup_amount':total_amt, - 'user_signature':data_user.name, - 'company_name':data_user.company_id.name, - 'company_currency':data_user.company_id.currency_id.name, - 'line':move_line, - 'heading': head, - 'date':time.strftime('%Y-%m-%d'), - } - body = body%val - sub = tools.ustr(data.email_subject) - msg = '' - if dest: - try: - vals = {'state': 'outgoing', - 'subject': sub, - 'body_html': '
%s
' % body, - 'email_to': dest, - 'email_from': data_user.email or tools.config.options['email_from']} - self.pool.get('mail.mail').create(cr, uid, vals, context=context) - msg_sent += partner.name + '\n' - except Exception, e: - raise osv.except_osv('Error !', e ) - else: - msg += partner.name + '\n' - msg_unsent += msg - if not msg_unsent: - summary = _("All Emails have been successfully sent to Partners:.\n\n%s") % msg_sent - else: - msg_unsent = _("Email not sent to following Partners, Email not available !\n\n%s") % msg_unsent - msg_sent = msg_sent and _("\n\nEmail sent to following Partners successfully. !\n\n%s") % msg_sent - line = '==========================================================================' - summary = msg_unsent + line + msg_sent - context.update({'summary': summary}) - else: - context.update({'summary': '\n\n\nEmail has not been sent to any partner. If you want to send it, please tick send email confirmation on wizard.'}) - - return { - 'name': _('Followup Summary'), - 'view_type': 'form', - 'context': context, - 'view_mode': 'tree,form', - 'res_model': 'account.followup.print.all', - 'views': [(resource_id,'form')], - 'type': 'ir.actions.act_window', - 'target': 'new', - 'nodestroy': True - } + +# mod_obj = self.pool.get('ir.model.data') +# move_obj = self.pool.get('account.move.line') +# user_obj = self.pool.get('res.users') +# +# if context is None: +# context = {} +# data = self.browse(cr, uid, ids, context=context)[0] +# stat_by_partner_line_ids = [partner_id.id for partner_id in data.partner_ids] +# partners = [stat_by_partner_line / 10000 for stat_by_partner_line in stat_by_partner_line_ids] +# model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all_msg')], context=context) +# resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] +# if True: #should not depend on this +# msg_sent = '' +# msg_unsent = '' +# data_user = user_obj.browse(cr, uid, uid, context=context) +# for partner in self.pool.get('res.partner').browse(cr, uid, partners, context=context): +# if partner.next_followup_level_id.send_email: +# ids_lines = move_obj.search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable']),('company_id','=',context.get('company_id', False))]) +# data_lines = move_obj.browse(cr, uid, ids_lines, context=context) +# total_amt = 0.0 +# for line in data_lines: +# total_amt += line.debit - line.credit +# dest = False +# if partner: +# dest = [partner.email] +# if not data.partner_lang: +# body = data.email_body +# else: +# cxt = context.copy() +# cxt['lang'] = partner.lang +# body = user_obj.browse(cr, uid, uid, context=cxt).company_id.follow_up_msg +# move_line = '' +# subtotal_due = 0.0 +# subtotal_paid = 0.0 +# subtotal_maturity = 0.0 +# balance = 0.0 +# l = '--------------------------------------------------------------------------------------------------------------------------' +# head = l+ '\n' + 'Date'.rjust(10) + '\t' + 'Description'.rjust(10) + '\t' + 'Ref'.rjust(10) + '\t' + 'Due date'.rjust(10) + '\t' + 'Due'.rjust(10) + '\t' + 'Paid'.rjust(10) + '\t' + 'Maturity'.rjust(10) + '\t' + 'Litigation'.rjust(10) + '\n' + l +# for i in data_lines: +# maturity = 0.00 +# if i.date_maturity < time.strftime('%Y-%m-%d') and (i.debit - i.credit): +# maturity = i.debit - i.credit +# subtotal_due = subtotal_due + i.debit +# subtotal_paid = subtotal_paid + i.credit +# subtotal_maturity = subtotal_maturity + int(maturity) +# balance = balance + (i.debit - i.credit) +# 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' +# 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' +# move_line = move_line + '\t\t\t' + 'Balance'.rjust(33) + '\t' + str(balance).rjust(10) + '\n' + l +# val = { +# 'partner_name':partner.name, +# 'followup_amount':total_amt, +# 'user_signature':data_user.name, +# 'company_name':data_user.company_id.name, +# 'company_currency':data_user.company_id.currency_id.name, +# 'line':move_line, +# 'heading': head, +# 'date':time.strftime('%Y-%m-%d'), +# } +# body = body%val +# sub = tools.ustr(data.email_subject) +# msg = '' +# if dest: +# try: +# vals = {'state': 'outgoing', +# 'subject': sub, +# 'body_html': '
%s
' % body, +# 'email_to': dest, +# 'email_from': data_user.email or tools.config.options['email_from']} +# self.pool.get('mail.mail').create(cr, uid, vals, context=context) +# msg_sent += partner.name + '\n' +# except Exception, e: +# raise osv.except_osv('Error !', e ) +# else: +# msg += partner.name + '\n' +# msg_unsent += msg +# if not msg_unsent: +# summary = _("All Emails have been successfully sent to Partners:.\n\n%s") % msg_sent +# else: +# msg_unsent = _("Email not sent to following Partners, Email not available !\n\n%s") % msg_unsent +# msg_sent = msg_sent and _("\n\nEmail sent to following Partners successfully. !\n\n%s") % msg_sent +# line = '==========================================================================' +# summary = msg_unsent + line + msg_sent +# context.update({'summary': summary}) +# else: +# context.update({'summary': '\n\n\nEmail has not been sent to any partner. If you want to send it, please tick send email confirmation on wizard.'}) +# +# return { +# 'name': _('Followup Summary'), +# 'view_type': 'form', +# 'context': context, +# 'view_mode': 'tree,form', +# 'res_model': 'account.followup.print.all', +# 'views': [(resource_id,'form')], +# 'type': 'ir.actions.act_window', +# 'target': 'new', +# 'nodestroy': True +# } def do_print(self, cr, uid, ids, context=None): if context is None: @@ -352,30 +388,35 @@ class account_followup_print_all(osv.osv_memory): 'datas': datas, } - def do_process(self, cr, uid, ids, context=None): - resu = self.do_mail(cr,uid,ids,context) - mod_obj = self.pool.get('ir.model.data') - move_obj = self.pool.get('account.move.line') - user_obj = self.pool.get('res.users') - if context is None: - context = {} - data = self.browse(cr, uid, ids, context=context)[0] - stat_by_partner_line_ids = [partner_id.id for partner_id in data.partner_ids] - partners = [stat_by_partner_line / 10000 for stat_by_partner_line in stat_by_partner_line_ids] - model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all_msg')], context=context) - resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] - print "start changeof new action..." - partnersfilt = [] - partner_obj = self.pool.get('res.partner') - for partner in partner_obj.browse(cr, uid, partners, context): - if partner.next_followup_level_id.phonecall: - partnersfilt.append(partner.id) - print "Should have been changed" - print partner.name - partner_obj = self.pool.get('res.partner').write(cr, uid, partnersfilt, {'payment_new_action': "Take your phone and call him, please!!!"}) - resu2 = self.do_print(cr,uid,ids,context) - return resu2 + + + + +#jco tests +# resu = self.do_mail(cr,uid,ids,context) +# mod_obj = self.pool.get('ir.model.data') +# move_obj = self.pool.get('account.move.line') +# user_obj = self.pool.get('res.users') +# if context is None: +# context = {} +# data = self.browse(cr, uid, ids, context=context)[0] +# stat_by_partner_line_ids = [partner_id.id for partner_id in data.partner_ids] +# partners = [stat_by_partner_line / 10000 for stat_by_partner_line in stat_by_partner_line_ids] +# model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all_msg')], context=context) +# resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] +# print "start changeof new action..." +# +# partnersfilt = [] +# partner_obj = self.pool.get('res.partner') +# for partner in partner_obj.browse(cr, uid, partners, context): +# if partner.next_followup_level_id.phonecall: +# partnersfilt.append(partner.id) +# print "Should have been changed" +# print partner.name +# partner_obj = self.pool.get('res.partner').write(cr, uid, partnersfilt, {'payment_new_action': "Take your phone and call him, please!!!"}) +# resu2 = self.do_print(cr,uid,ids,context) +# return resu2 account_followup_print_all() From c953d9978c0e847f40ceffb2485f842695511190 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 26 Oct 2012 10:09:14 +0200 Subject: [PATCH 09/38] before merge from trunk bzr revid: jco@openerp.com-20121026080914-8az79d9rkbfoucyf --- addons/account_followup/account_followup.py | 146 ++++++++++++++- .../wizard/account_followup_print.py | 168 +++++------------- .../wizard/account_followup_print_view.xml | 12 +- 3 files changed, 188 insertions(+), 138 deletions(-) diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index d0e9da38e52..0da848aa1f2 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -188,6 +188,150 @@ class res_partner(osv.osv): #Now search one level higher return res + + def do_partner_phonecall(self, cr, uid, partner_ids, context=None): + #partners = self.browse(cr, uid, partner_ids, context) + print partner_ids + self.write(cr, uid, partner_ids, {'payment_next_action': 'Phone...'}, context) + + def do_partner_print(self, cr, uid, partner_ids, data, context=None): + #data.update({'date': context['date']}) + if not partner_ids: + return {} + data['partner_ids'] = partner_ids + print data + datas = { + 'ids': [], + 'model': 'account_followup.followup', + 'form': data + } + + return { + 'type': 'ir.actions.report.xml', + 'report_name': 'account_followup.followup.print', + 'datas': datas, + } + + def do_partner_mail(self, cr, uid, partner_ids, context=None): + #get the mail template to use + mail_template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_followup', 'email_template_account_followup') + mtp = self.pool.get('email.template') + #mtp.subject = "Invoices overdue" + + #user_obj = self.pool.get('res.users') + + #mtp.email_from = user_obj.browse(cr, uid, uid, context=context) + for partner in self.browse(cr, uid, partner_ids, context): + pass + # mtp.send_mail(cr, uid, partner.id, mail_template_id, context=context) + + + #complete the mail body with partner information + #(to be discussed with fp) attach the report to the mail or include the move lines in the mail body + #send the mail (need to check the function name) + + +# mod_obj = self.pool.get('ir.model.data') +# move_obj = self.pool.get('account.move.line') +# user_obj = self.pool.get('res.users') +# +# if context is None: +# context = {} +# data = self.browse(cr, uid, ids, context=context)[0] +# stat_by_partner_line_ids = [partner_id.id for partner_id in data.partner_ids] +# partners = [stat_by_partner_line / 10000 for stat_by_partner_line in stat_by_partner_line_ids] +# model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all_msg')], context=context) +# resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] +# if True: #should not depend on this +# msg_sent = '' +# msg_unsent = '' +# data_user = user_obj.browse(cr, uid, uid, context=context) +# for partner in self.pool.get('res.partner').browse(cr, uid, partners, context=context): +# if partner.next_followup_level_id.send_email: +# ids_lines = move_obj.search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable']),('company_id','=',context.get('company_id', False))]) +# data_lines = move_obj.browse(cr, uid, ids_lines, context=context) +# total_amt = 0.0 +# for line in data_lines: +# total_amt += line.debit - line.credit +# dest = False +# if partner: +# dest = [partner.email] +# if not data.partner_lang: +# body = data.email_body +# else: +# cxt = context.copy() +# cxt['lang'] = partner.lang +# body = user_obj.browse(cr, uid, uid, context=cxt).company_id.follow_up_msg +# move_line = '' +# subtotal_due = 0.0 +# subtotal_paid = 0.0 +# subtotal_maturity = 0.0 +# balance = 0.0 +# l = '--------------------------------------------------------------------------------------------------------------------------' +# head = l+ '\n' + 'Date'.rjust(10) + '\t' + 'Description'.rjust(10) + '\t' + 'Ref'.rjust(10) + '\t' + 'Due date'.rjust(10) + '\t' + 'Due'.rjust(10) + '\t' + 'Paid'.rjust(10) + '\t' + 'Maturity'.rjust(10) + '\t' + 'Litigation'.rjust(10) + '\n' + l +# for i in data_lines: +# maturity = 0.00 +# if i.date_maturity < time.strftime('%Y-%m-%d') and (i.debit - i.credit): +# maturity = i.debit - i.credit +# subtotal_due = subtotal_due + i.debit +# subtotal_paid = subtotal_paid + i.credit +# subtotal_maturity = subtotal_maturity + int(maturity) +# balance = balance + (i.debit - i.credit) +# 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' +# 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' +# move_line = move_line + '\t\t\t' + 'Balance'.rjust(33) + '\t' + str(balance).rjust(10) + '\n' + l +# val = { +# 'partner_name':partner.name, +# 'followup_amount':total_amt, +# 'user_signature':data_user.name, +# 'company_name':data_user.company_id.name, +# 'company_currency':data_user.company_id.currency_id.name, +# 'line':move_line, +# 'heading': head, +# 'date':time.strftime('%Y-%m-%d'), +# } +# body = body%val +# sub = tools.ustr(data.email_subject) +# msg = '' +# if dest: +# try: +# vals = {'state': 'outgoing', +# 'subject': sub, +# 'body_html': '
%s
' % body, +# 'email_to': dest, +# 'email_from': data_user.email or tools.config.options['email_from']} +# self.pool.get('mail.mail').create(cr, uid, vals, context=context) +# msg_sent += partner.name + '\n' +# except Exception, e: +# raise osv.except_osv('Error !', e ) +# else: +# msg += partner.name + '\n' +# msg_unsent += msg +# if not msg_unsent: +# summary = _("All Emails have been successfully sent to Partners:.\n\n%s") % msg_sent +# else: +# msg_unsent = _("Email not sent to following Partners, Email not available !\n\n%s") % msg_unsent +# msg_sent = msg_sent and _("\n\nEmail sent to following Partners successfully. !\n\n%s") % msg_sent +# line = '==========================================================================' +# summary = msg_unsent + line + msg_sent +# context.update({'summary': summary}) +# else: +# context.update({'summary': '\n\n\nEmail has not been sent to any partner. If you want to send it, please tick send email confirmation on wizard.'}) +# +# return { +# 'name': _('Followup Summary'), +# 'view_type': 'form', +# 'context': context, +# 'view_mode': 'tree,form', +# 'res_model': 'account.followup.print.all', +# 'views': [(resource_id,'form')], +# 'type': 'ir.actions.act_window', +# 'target': 'new', +# 'nodestroy': True +# } + + + _inherit = "res.partner" _columns = { 'payment_responsible_id':fields.many2one('res.users', ondelete='set null', string='Responsible', help="Responsible"), @@ -201,8 +345,8 @@ class res_partner(osv.osv): 'latest_followup_level_id':fields.function(_get_latest_followup_level_id, method=True, type='many2one', relation='account_followup.followup.line', string="latest followup level", store=True), 'next_followup_level_id':fields.function(_get_next_followup_level_id, method=True, type='many2one', relation='account_followup.followup.line', string="next level"), - } + } res_partner() diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py index e3366af8041..262f4e43403 100644 --- a/addons/account_followup/wizard/account_followup_print.py +++ b/addons/account_followup/wizard/account_followup_print.py @@ -79,6 +79,14 @@ class account_followup_print(osv.osv_memory): _columns = { 'date': fields.date('Follow-up Sending Date', required=True, help="This field allow you to select a forecast date to plan your follow-ups"), 'followup_id': fields.many2one('account_followup.followup', 'Follow-Up', required=True, readonly = True), + 'partner_ids': fields.many2many('account_followup.stat.by.partner', 'partner_stat_rel', 'osv_memory_id', 'partner_id', 'Partners', required=True), + 'company_id':fields.related('followup_id', 'company_id', type='many2one', relation='res.company'), + #'email_conf': fields.boolean('Send Email Confirmation'), + #'email_subject': fields.char('Email Subject', size=64), + #'partner_lang': fields.boolean('Send Email in Partner Language', help='Do not change message text, if you want to send email in partner language, or configure from company'), + #'email_body': fields.text('Email Body'), + 'summary': fields.text('Summary', required=True, readonly=True), + 'test_print': fields.boolean('Test Print', help='Check if you want to print follow-ups without changing follow-ups level.') } def _get_followup(self, cr, uid, context=None): @@ -115,19 +123,28 @@ class account_followup_print(osv.osv_memory): 'followup_id': _get_followup, } - def process_partner(self, cr, uid, partner_id, context=None): - partner = self.pool.get('account_followup.stat.by.partner').browse(cr, uid, partner_id, context=context) - if partner.next_followup_level_id.phonecall: - self.do_partner_phonecall(cr, uid, partner_id, context) - if partner.next_followup_level_id.mail: - self.do_partner_mail() - if partner.next_followup_level_id.manual: - self.do_partner_manual() - def do_update_followup_level(self, cr, uid, to_update, context=None): + + def process_partners(self, cr, uid, partner_ids, data, context=None): + partner_obj = self.pool.get('res.partner') + partner_ids_to_print = [] + for partner in self.pool.get('account_followup.stat.by.partner').browse(cr, uid, partner_ids, context=context): + if partner.max_followup_id.phonecall: + partner_obj.do_partner_phonecall(cr, uid, [partner.id], context) + if partner.max_followup_id.send_email: + partner_obj.do_partner_mail(cr, uid, [partner.id], context) + if partner.max_followup_id.send_letter: + partner_ids_to_print.append(partner.id) + + action = partner_obj.do_partner_print(cr, uid, partner_ids_to_print, data, context) + return action or {} + + + def do_update_followup_level(self, cr, uid, to_update, partner_list, date, context=None): #update the followupo level on account.move.line for id in to_update.keys(): - if to_update[id]['partner_id'] in data['partner_ids']: + if to_update[id]['partner_id'] in partner_list: + cr.execute( "UPDATE account_move_line "\ "SET followup_line_id=%s, followup_date=%s "\ @@ -139,9 +156,12 @@ class account_followup_print(osv.osv_memory): tmp = self._get_partners_followp(cr, uid, ids, context=context) partner_list = tmp['partner_ids'] to_update = tmp['to_update'] - self.do_update_followup_level(cr, uid, to_update, context=context) - for partner in partner_list: - process_partner(cr, uid, partner, context=context) + date = self.browse(cr, uid, ids, context)[0].date + data = self.read(cr, uid, ids, [], context)[0] + self.do_update_followup_level(cr, uid, to_update, partner_list, date, context=context) + res = self.process_partners(cr, uid, partner_list, data, context=context) + return res + #account_followup_print() @@ -177,13 +197,9 @@ class account_followup_print(osv.osv_memory): # } def _get_partners_followp(self, cr, uid, ids, context=None): - data = {} - if context is None: - context = {} - if ids: - data = self.browse(cr, uid, ids, context=context)[0] - company_id = 'company_id' in context and context['company_id'] or data.company_id.id - + data = {} + data = self.browse(cr, uid, ids, context=context)[0] + company_id = data.company_id.id cr.execute( "SELECT l.partner_id, l.followup_line_id,l.date_maturity, l.date, l.id "\ @@ -250,112 +266,8 @@ class account_followup_print(osv.osv_memory): return {'partner_ids': partner_list, 'to_update': to_update} - def do_partner_mail(self, cr, uid, partner_ids, context=None): - #get the mail template to use - mail_template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_followup', 'email_template_account_followup', context=context) - #complete the mail body with partner information - #(to be discussed with fp) attach the report to the mail or include the move lines in the mail body - #send the mail (need to check the function name) - -# mod_obj = self.pool.get('ir.model.data') -# move_obj = self.pool.get('account.move.line') -# user_obj = self.pool.get('res.users') -# -# if context is None: -# context = {} -# data = self.browse(cr, uid, ids, context=context)[0] -# stat_by_partner_line_ids = [partner_id.id for partner_id in data.partner_ids] -# partners = [stat_by_partner_line / 10000 for stat_by_partner_line in stat_by_partner_line_ids] -# model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all_msg')], context=context) -# resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] -# if True: #should not depend on this -# msg_sent = '' -# msg_unsent = '' -# data_user = user_obj.browse(cr, uid, uid, context=context) -# for partner in self.pool.get('res.partner').browse(cr, uid, partners, context=context): -# if partner.next_followup_level_id.send_email: -# ids_lines = move_obj.search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable']),('company_id','=',context.get('company_id', False))]) -# data_lines = move_obj.browse(cr, uid, ids_lines, context=context) -# total_amt = 0.0 -# for line in data_lines: -# total_amt += line.debit - line.credit -# dest = False -# if partner: -# dest = [partner.email] -# if not data.partner_lang: -# body = data.email_body -# else: -# cxt = context.copy() -# cxt['lang'] = partner.lang -# body = user_obj.browse(cr, uid, uid, context=cxt).company_id.follow_up_msg -# move_line = '' -# subtotal_due = 0.0 -# subtotal_paid = 0.0 -# subtotal_maturity = 0.0 -# balance = 0.0 -# l = '--------------------------------------------------------------------------------------------------------------------------' -# head = l+ '\n' + 'Date'.rjust(10) + '\t' + 'Description'.rjust(10) + '\t' + 'Ref'.rjust(10) + '\t' + 'Due date'.rjust(10) + '\t' + 'Due'.rjust(10) + '\t' + 'Paid'.rjust(10) + '\t' + 'Maturity'.rjust(10) + '\t' + 'Litigation'.rjust(10) + '\n' + l -# for i in data_lines: -# maturity = 0.00 -# if i.date_maturity < time.strftime('%Y-%m-%d') and (i.debit - i.credit): -# maturity = i.debit - i.credit -# subtotal_due = subtotal_due + i.debit -# subtotal_paid = subtotal_paid + i.credit -# subtotal_maturity = subtotal_maturity + int(maturity) -# balance = balance + (i.debit - i.credit) -# 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' -# 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' -# move_line = move_line + '\t\t\t' + 'Balance'.rjust(33) + '\t' + str(balance).rjust(10) + '\n' + l -# val = { -# 'partner_name':partner.name, -# 'followup_amount':total_amt, -# 'user_signature':data_user.name, -# 'company_name':data_user.company_id.name, -# 'company_currency':data_user.company_id.currency_id.name, -# 'line':move_line, -# 'heading': head, -# 'date':time.strftime('%Y-%m-%d'), -# } -# body = body%val -# sub = tools.ustr(data.email_subject) -# msg = '' -# if dest: -# try: -# vals = {'state': 'outgoing', -# 'subject': sub, -# 'body_html': '
%s
' % body, -# 'email_to': dest, -# 'email_from': data_user.email or tools.config.options['email_from']} -# self.pool.get('mail.mail').create(cr, uid, vals, context=context) -# msg_sent += partner.name + '\n' -# except Exception, e: -# raise osv.except_osv('Error !', e ) -# else: -# msg += partner.name + '\n' -# msg_unsent += msg -# if not msg_unsent: -# summary = _("All Emails have been successfully sent to Partners:.\n\n%s") % msg_sent -# else: -# msg_unsent = _("Email not sent to following Partners, Email not available !\n\n%s") % msg_unsent -# msg_sent = msg_sent and _("\n\nEmail sent to following Partners successfully. !\n\n%s") % msg_sent -# line = '==========================================================================' -# summary = msg_unsent + line + msg_sent -# context.update({'summary': summary}) -# else: -# context.update({'summary': '\n\n\nEmail has not been sent to any partner. If you want to send it, please tick send email confirmation on wizard.'}) -# -# return { -# 'name': _('Followup Summary'), -# 'view_type': 'form', -# 'context': context, -# 'view_mode': 'tree,form', -# 'res_model': 'account.followup.print.all', -# 'views': [(resource_id,'form')], -# 'type': 'ir.actions.act_window', -# 'target': 'new', -# 'nodestroy': True -# } + def do_print(self, cr, uid, ids, context=None): if context is None: @@ -376,7 +288,7 @@ class account_followup_print(osv.osv_memory): (to_update[id]['level'], date, int(id),)) data.update({'date': context['date']}) - print data + datas = { 'ids': [], 'model': 'account_followup.followup', @@ -406,7 +318,7 @@ class account_followup_print(osv.osv_memory): # model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all_msg')], context=context) # resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] # print "start changeof new action..." -# +# # partnersfilt = [] # partner_obj = self.pool.get('res.partner') # for partner in partner_obj.browse(cr, uid, partners, context): @@ -419,6 +331,6 @@ class account_followup_print(osv.osv_memory): # return resu2 -account_followup_print_all() +#account_followup_print_all() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account_followup/wizard/account_followup_print_view.xml b/addons/account_followup/wizard/account_followup_print_view.xml index e8ea58aa2b3..c9992954445 100644 --- a/addons/account_followup/wizard/account_followup_print_view.xml +++ b/addons/account_followup/wizard/account_followup_print_view.xml @@ -12,7 +12,7 @@
-
@@ -63,7 +63,7 @@
- + From 4cedd4a505671e4e50dbf40d1e1fbe866cbbaf91 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 26 Oct 2012 13:23:31 +0200 Subject: [PATCH 10/38] [IMP] wizard default values work bzr revid: jco@openerp.com-20121026112331-k5aphdh5tfani5s1 --- .../account_followup/wizard/account_followup_print.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py index 74b6571f347..a9646b1733c 100644 --- a/addons/account_followup/wizard/account_followup_print.py +++ b/addons/account_followup/wizard/account_followup_print.py @@ -118,10 +118,7 @@ class account_followup_print(osv.osv_memory): # 'target': 'new', # } - _defaults = { - 'date': lambda *a: time.strftime('%Y-%m-%d'), - 'followup_id': _get_followup, - } + @@ -173,12 +170,14 @@ class account_followup_print(osv.osv_memory): return self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.follow_up_msg _defaults = { - 'email_body': _get_msg, + 'date': lambda *a: time.strftime('%Y-%m-%d'), + 'followup_id': _get_followup, + 'email_body': _get_msg, 'email_subject': _('Invoices Reminder'), 'partner_lang': True, 'partner_ids': _get_partners, 'summary': _get_summary, - } + } #account_followup_print() From 1453d24688447f79a1f582cae76c719e90225674 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 26 Oct 2012 13:34:54 +0200 Subject: [PATCH 11/38] Removed partner_ids default bzr revid: jco@openerp.com-20121026113454-h0l4xlledmnkhohs --- .../wizard/account_followup_print.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py index a9646b1733c..a0ecd86ce45 100644 --- a/addons/account_followup/wizard/account_followup_print.py +++ b/addons/account_followup/wizard/account_followup_print.py @@ -163,19 +163,19 @@ class account_followup_print(osv.osv_memory): context = {} return context.get('summary', '') - def _get_partners(self, cr, uid, context=None): - return self._get_partners_followp(cr, uid, [], context=context)['partner_ids'] + #def _get_partners(self, cr, uid, context=None): + # return self._get_partners_followp(cr, uid, [], context=context)['partner_ids'] def _get_msg(self, cr, uid, context=None): return self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.follow_up_msg _defaults = { - 'date': lambda *a: time.strftime('%Y-%m-%d'), - 'followup_id': _get_followup, - 'email_body': _get_msg, + 'date': lambda *a: time.strftime('%Y-%m-%d'), + 'followup_id': _get_followup, + 'email_body': _get_msg, 'email_subject': _('Invoices Reminder'), 'partner_lang': True, - 'partner_ids': _get_partners, + #'partner_ids': _get_partners, 'summary': _get_summary, } #account_followup_print() From 81a802b22bad49857ee98097fb9a6798ef69980f Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 26 Oct 2012 17:11:25 +0200 Subject: [PATCH 12/38] [IMP] Solved error printing tuple many2one bzr revid: jco@openerp.com-20121026151125-utppa71g4a5a53c5 --- addons/account_followup/account_followup.py | 33 ++++++++++--------- .../account_followup_data.xml | 3 +- .../account_followup_view.xml | 1 + .../wizard/account_followup_print.py | 4 ++- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index 25338677c6d..14362eca733 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -21,6 +21,7 @@ from osv import fields, osv from datetime import date +import time class followup(osv.osv): _name = 'account_followup.followup' @@ -50,6 +51,7 @@ class followup_line(osv.osv): 'send_email':fields.boolean('Send email', help="When processing, it will send an email"), 'send_letter':fields.boolean('Print email'), 'phonecall':fields.boolean('Phone call'), + 'email_template_id':fields.many2one('email.template', 'Email template', required = False, ondelete='set null') } _defaults = { 'start': 'days', @@ -143,12 +145,11 @@ class res_partner(osv.osv): for partner in self.browse(cr, uid, ids): amls = partner.accountmoveline_ids level_id = 0 - level_days = -1000 #TO BE IMPROVED with boolean checking first time or by using MAX + level_days = False #TO BE IMPROVED with boolean checking first time or by using MAX latest_level = False res[partner.id] = False - for accountmoveline in amls: - if (accountmoveline.followup_line_id != False) and (level_days < accountmoveline.followup_line_id.delay): + if (accountmoveline.followup_line_id != False) and (not level_days or level_days < accountmoveline.followup_line_id.delay): # and (accountmoveline.debit > 0): (accountmoveline.state != "draft") and #and (accountmoveline.reconcile_id == None) level_days = accountmoveline.followup_line_id.delay @@ -177,9 +178,9 @@ class res_partner(osv.osv): old_delay = latest.delay else: old_delay = False - - for fl in self.pool.get('account_followup.followup.line').search(cr, uid, []): #('followup_id.company_id','=',latest.followup_id.company_id) - fl_obj = self.pool.get('account_followup.followup.line').browse(cr, uid, [fl])[0] + fl_ar = self.pool.get('account_followup.followup.line').search(cr, uid, [('followup_id.company_id.id','=', partner.company_id.id)]) + + for fl_obj in self.pool.get('account_followup.followup.line').browse(cr, uid, fl_ar): if not old_delay: if not delay or fl_obj.delay < delay: delay = fl_obj.delay @@ -193,19 +194,18 @@ class res_partner(osv.osv): return res - def do_partner_phonecall(self, cr, uid, partner_ids, context=None): + def do_partner_phonecall(self, cr, uid, partner_ids, context=None): #partners = self.browse(cr, uid, partner_ids, context) - print partner_ids - #for partner in self.browse(cr, uid, partner_ids, context): - # print partner.is_company - self.write(cr, uid, partner_ids, {'payment_note': 'Phone...'}, context) + #print partner_ids + self.write(cr, uid, partner_ids, {'payment_next_date': fields.date.context_today(cr, uid, context), 'payment_next_action':'Phony'}, context) + + def do_partner_print(self, cr, uid, partner_ids, data, context=None): #data.update({'date': context['date']}) if not partner_ids: return {} data['partner_ids'] = partner_ids - print data datas = { 'ids': [], 'model': 'account_followup.followup', @@ -229,9 +229,12 @@ class res_partner(osv.osv): #mtp.email_from = user_obj.browse(cr, uid, uid, context=context) for partner in self.browse(cr, uid, partner_ids, context): pass - # mtp.send_mail(cr, uid, partner.id, mail_template_id, context=context) - - + #Get max level of ids +# if partner.latest_followup_level_id.email_template_id != False: +# mtp.send_mail(cr, uid, partner.id, partner.latest_followup_level_id.email_template_id.id, context=context) +# else: +# mtp.send_mail(cr, uid, partner.id, mail_template_id.id, context=context) + #complete the mail body with partner information #(to be discussed with fp) attach the report to the mail or include the move lines in the mail body #send the mail (need to check the function name) diff --git a/addons/account_followup/account_followup_data.xml b/addons/account_followup/account_followup_data.xml index a14f32b2747..05df2b9a179 100644 --- a/addons/account_followup/account_followup_data.xml +++ b/addons/account_followup/account_followup_data.xml @@ -10,11 +10,12 @@ ${object.user_id.email or ''} ${object.company_id.name} Followup ${object.email} + ${object.lang} -TYPE HERE THE MAIL CONTENT YOU WANT + ${object.latest_followup_level_id.description}

Hello${object.partner_id.name and ' ' or ''}${object.partner_id.name or ''},

Here is your ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} from ${object.company_id.name}:

diff --git a/addons/account_followup/account_followup_view.xml b/addons/account_followup/account_followup_view.xml index f15395d1c33..1a080d71b45 100644 --- a/addons/account_followup/account_followup_view.xml +++ b/addons/account_followup/account_followup_view.xml @@ -30,6 +30,7 @@ + diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py index a0ecd86ce45..f926c1f1b16 100644 --- a/addons/account_followup/wizard/account_followup_print.py +++ b/addons/account_followup/wizard/account_followup_print.py @@ -80,7 +80,7 @@ class account_followup_print(osv.osv_memory): 'date': fields.date('Follow-up Sending Date', required=True, help="This field allow you to select a forecast date to plan your follow-ups"), 'followup_id': fields.many2one('account_followup.followup', 'Follow-Up', required=True, readonly = True), 'partner_ids': fields.many2many('account_followup.stat.by.partner', 'partner_stat_rel', 'osv_memory_id', 'partner_id', 'Partners', required=True), - 'company_id':fields.related('followup_id', 'company_id', type='many2one', relation='res.company'), + 'company_id':fields.related('followup_id', 'company_id', type='many2one', relation='res.company', store=True, readonly=True), 'email_conf': fields.boolean('Send Email Confirmation'), 'email_subject': fields.char('Email Subject', size=64), 'partner_lang': fields.boolean('Send Email in Partner Language', help='Do not change message text, if you want to send email in partner language, or configure from company'), @@ -132,6 +132,7 @@ class account_followup_print(osv.osv_memory): partner_obj.do_partner_mail(cr, uid, [partner.partner_id.id], context) if partner.max_followup_id.send_letter: partner_ids_to_print.append(partner.id) + action = partner_obj.do_partner_print(cr, uid, partner_ids_to_print, data, context) return action or {} @@ -154,6 +155,7 @@ class account_followup_print(osv.osv_memory): to_update = tmp['to_update'] date = self.browse(cr, uid, ids, context)[0].date data = self.read(cr, uid, ids, [], context)[0] + data['followup_id'] = data['followup_id'][0] self.do_update_followup_level(cr, uid, to_update, partner_list, date, context=context) res = self.process_partners(cr, uid, partner_list, data, context=context) return res From c74e937b0d9e0cc2a879c3ba712de3c74f0931d4 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 29 Oct 2012 10:29:01 +0100 Subject: [PATCH 13/38] Adjusted email template bzr revid: jco@openerp.com-20121029092901-gc8y4d1o04ijexkb --- addons/account_followup/account_followup.py | 20 +++-- .../account_followup_data.xml | 88 ++----------------- 2 files changed, 18 insertions(+), 90 deletions(-) diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index 14362eca733..2fdc1e3969a 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -197,7 +197,9 @@ class res_partner(osv.osv): def do_partner_phonecall(self, cr, uid, partner_ids, context=None): #partners = self.browse(cr, uid, partner_ids, context) #print partner_ids - self.write(cr, uid, partner_ids, {'payment_next_date': fields.date.context_today(cr, uid, context), 'payment_next_action':'Phony'}, context) + print "Testing: " , fields.date.context_today(cr, uid, context) + self.write(cr, uid, partner_ids, {'payment_next_action_date': fields.date.context_today(cr, uid, context), 'payment_next_action' : 'Phoning'}, context) + @@ -223,18 +225,18 @@ class res_partner(osv.osv): mail_template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_followup', 'email_template_account_followup') mtp = self.pool.get('email.template') #mtp.subject = "Invoices overdue" - #user_obj = self.pool.get('res.users') - #mtp.email_from = user_obj.browse(cr, uid, uid, context=context) for partner in self.browse(cr, uid, partner_ids, context): - pass + #Get max level of ids -# if partner.latest_followup_level_id.email_template_id != False: -# mtp.send_mail(cr, uid, partner.id, partner.latest_followup_level_id.email_template_id.id, context=context) -# else: -# mtp.send_mail(cr, uid, partner.id, mail_template_id.id, context=context) - + if partner.latest_followup_level_id.email_template_id != False: + #print "From latest followup level", partner.latest_followup_level_id.email_template_id.id + mtp.send_mail(cr, uid, partner.latest_followup_level_id.email_template_id.id, partner.id, context=context) + else: + #print "From mail template", mail_template_id.id + mtp.send_mail(cr, uid, mail_template_id.id, partner.id, context=context) + #complete the mail body with partner information #(to be discussed with fp) attach the report to the mail or include the move lines in the mail body #send the mail (need to check the function name) diff --git a/addons/account_followup/account_followup_data.xml b/addons/account_followup/account_followup_data.xml index 05df2b9a179..85a8f493189 100644 --- a/addons/account_followup/account_followup_data.xml +++ b/addons/account_followup/account_followup_data.xml @@ -6,7 +6,7 @@ - + Followup of outstanding accounts ${object.user_id.email or ''} ${object.company_id.name} Followup ${object.email} @@ -16,94 +16,20 @@ ${object.latest_followup_level_id.description} -

Hello${object.partner_id.name and ' ' or ''}${object.partner_id.name or ''},

+

Hello${object.name and ' ' or ''},

-

Here is your ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} from ${object.company_id.name}:

+

We see in our books that some accounts are not settled yet:

+ + <%for aml in ${object.accountmoveline_ids}> + ${aml.debit} + <%endfor>

  REFERENCES
  Order number: ${object.name}
-   Order total: ${object.amount_total} ${object.pricelist_id.currency_id.name}
-   Order date: ${object.date_order}
- % if object.origin: -   Order reference: ${object.origin}
- % endif - % if object.client_order_ref: -   Your reference: ${object.client_order_ref}
- % endif   Your contact: ${object.user_id.name}

- -

- Testing -


- - - - - -

- You can view the ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} document, download it and pay online using the following link: -

- View Order - - % if object.order_policy in ('prepaid','manual') and object.company_id.paypal_account and object.state not in ('draft', 'sent'): - <% - comp_name = quote(object.company_id.name) - order_name = quote(object.name) - paypal_account = quote(object.company_id.paypal_account) - order_amount = quote(str(object.amount_total)) - cur_name = quote(object.pricelist_id.currency_id.name) - paypal_url = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=%s&item_name=%s%%20Order%%20%s" \ - "&invoice=%s&amount=%s&currency_code=%s&button_subtype=services&no_note=1" \ - "&bn=OpenERP_Order_PayNow_%s" % \ - (paypal_account,comp_name,order_name,order_name,order_amount,cur_name,cur_name) - %> -
-

It is also possible to directly pay with Paypal:

- - - - % endif - -
-

If you have any question, do not hesitate to contact us.

-

Thank you for choosing ${object.company_id.name or 'us'}!

-
-
-
-

- ${object.company_id.name}

-
-
- - % if object.company_id.street: - ${object.company_id.street}
- % endif - % if object.company_id.street2: - ${object.company_id.street2}
- % endif - % if object.company_id.city or object.company_id.zip: - ${object.company_id.zip} ${object.company_id.city}
- % endif - % if object.company_id.country_id: - ${object.company_id.state_id and ('%s, ' % object.company_id.state_id.name) or ''} ${object.company_id.country_id.name or ''}
- % endif -
- % if object.company_id.phone: -
- Phone:  ${object.company_id.phone} -
- % endif - % if object.company_id.website: - - %endif -

-
]]>
From 81b59fa65f3dc812dc02edff1e44ce0ef02374ef Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 29 Oct 2012 13:41:18 +0100 Subject: [PATCH 14/38] [WIP]: removing tests bzr revid: jco@openerp.com-20121029124118-w90vqg9c0opfk0ha --- .../account_followup_data.xml | 6 +-- .../test/account_followup.yml | 48 +++++++++---------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/addons/account_followup/account_followup_data.xml b/addons/account_followup/account_followup_data.xml index 85a8f493189..00da7fe3bde 100644 --- a/addons/account_followup/account_followup_data.xml +++ b/addons/account_followup/account_followup_data.xml @@ -15,14 +15,12 @@ - ${object.latest_followup_level_id.description} +

Hello${object.name and ' ' or ''},

We see in our books that some accounts are not settled yet:

- <%for aml in ${object.accountmoveline_ids}> - ${aml.debit} - <%endfor> +

  REFERENCES
diff --git a/addons/account_followup/test/account_followup.yml b/addons/account_followup/test/account_followup.yml index 06617b7af97..dcfdf6ef38f 100644 --- a/addons/account_followup/test/account_followup.yml +++ b/addons/account_followup/test/account_followup.yml @@ -10,27 +10,27 @@ - !record {model: account.followup.print, id: account_followup_print_0}: {} -- - I select the follow-up to send it to the partner. -- - !python {model: account.followup.print}: | - self.do_continue(cr, uid, [ref("account_followup_print_0")], {"active_ids": [ref("account_followup.account_followup_print_menu")], "active_id": ref("account_followup.account_followup_print_menu"), - }) -- - I select partners whom I want to send follow-ups. -- - !record {model: account.followup.print.all, id: account_followup_print_all_0}: - email_body: 'Date : %(date)s\n\nDear %(partner_name)s,\n\nPlease find in attachment - a reminder of all your unpaid invoices, for a total amount due of:\n\n%(followup_amount).2f - %(company_currency)s\n\nThanks,\n--\n%(user_signature)s\n%(company_name)s' - email_subject: Invoices Reminder - partner_ids: - - base.res_partner_12 - partner_lang: 1 -- - I send a follow-up mail to partner. -- - !python {model: account.followup.print.all}: | - import time - self.do_mail(cr, uid, [ref("account_followup_print_all_0")], {"active_ids": [ref("account_followup.account_followup_print_menu")], "date": time.strftime('%Y-%m-%d'), "followup_id": ref("account_followup.demo_followup1"), "active_id": ref("account_followup.account_followup_print_menu"), - }) +#- +# I select the follow-up to send it to the partner. +# - +# !python {model: account.followup.print}: | +# self.do_continue(cr, uid, [ref("account_followup_print_0")], {"active_ids": [ref("account_followup.account_followup_print_menu")], "active_id": ref("account_followup.account_followup_print_menu"), +# }) +# - +# I select partners whom I want to send follow-ups. +# - +# !record {model: account.followup.print.all, id: account_followup_print_all_0}: +# email_body: 'Date : %(date)s\n\nDear %(partner_name)s,\n\nPlease find in attachment +# a reminder of all your unpaid invoices, for a total amount due of:\n\n%(followup_amount).2f +# %(company_currency)s\n\nThanks,\n--\n%(user_signature)s\n%(company_name)s' +# email_subject: Invoices Reminder +# partner_ids: +# - base.res_partner_12 +# partner_lang: 1 +# - +# I send a follow-up mail to partner. +# - +# !python {model: account.followup.print.all}: | +# import time +# self.do_mail(cr, uid, [ref("account_followup_print_all_0")], {"active_ids": [ref("account_followup.account_followup_print_menu")], "date": time.strftime('%Y-%m-%d'), "followup_id": ref("account_followup.demo_followup1"), "active_id": ref("account_followup.account_followup_print_menu"), +# }) From ed5bc8a591243772ae85a116b1f531b2a7910c23 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Tue, 30 Oct 2012 12:05:21 +0100 Subject: [PATCH 15/38] [WIP] Changed tests + litigation bzr revid: jco@openerp.com-20121030110521-ojiq0bwbxgvqriee --- addons/account_followup/__openerp__.py | 2 +- addons/account_followup/account_followup.py | 23 ++++++++++++--- .../account_followup_customers.xml | 1 + .../account_followup_data.xml | 26 +++++++++++++++++ .../test/account_followup.yml | 29 ++++--------------- .../test/account_followup_report.yml | 10 ------- .../wizard/account_followup_print.py | 5 +++- 7 files changed, 56 insertions(+), 40 deletions(-) delete mode 100644 addons/account_followup/test/account_followup_report.yml diff --git a/addons/account_followup/__openerp__.py b/addons/account_followup/__openerp__.py index 6a5e144d6e0..acc4ea3ae41 100644 --- a/addons/account_followup/__openerp__.py +++ b/addons/account_followup/__openerp__.py @@ -61,7 +61,7 @@ Note that if you want to check the follow-up level for a given partner/account e 'demo': [], 'test': [ 'test/account_followup.yml', - 'test/account_followup_report.yml', + #'test/account_followup_report.yml', ], 'installable': True, 'auto_install': False, diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index 2fdc1e3969a..e058977dff5 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -194,11 +194,24 @@ class res_partner(osv.osv): return res + + def _get_amount(self, cr, uid, ids, name, arg, context=None): + ''' + Get the total outstanding amount in the account move lines + ''' + res={} + for partner in self.browse(cr, uid, ids, context): + res[partner.id] = 0.0 + for aml in partner.accountmoveline_ids: + res[partner.id] = res[partner.id] + aml.debit + return res + + def do_partner_phonecall(self, cr, uid, partner_ids, context=None): #partners = self.browse(cr, uid, partner_ids, context) #print partner_ids - print "Testing: " , fields.date.context_today(cr, uid, context) - self.write(cr, uid, partner_ids, {'payment_next_action_date': fields.date.context_today(cr, uid, context), 'payment_next_action' : 'Phoning'}, context) + #print "Testing: " , fields.date.context_today(cr, uid, context) + self.write(cr, uid, partner_ids, {'payment_next_action_date': fields.date.context_today(cr, uid, context),}, context) @@ -343,6 +356,7 @@ class res_partner(osv.osv): + _inherit = "res.partner" _columns = { 'payment_responsible_id':fields.many2one('res.users', ondelete='set null', string='Responsible', help="Responsible"), @@ -354,8 +368,9 @@ class res_partner(osv.osv): ('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')]), 'latest_followup_date':fields.function(_get_latest_followup_date, method=True, type='date', string="latest followup date", store=True), 'latest_followup_level_id':fields.function(_get_latest_followup_level_id, method=True, - type='many2one', relation='account_followup.followup.line', string="latest followup level", store=True), - 'next_followup_level_id':fields.function(_get_next_followup_level_id, method=True, type='many2one', relation='account_followup.followup.line', string="next level"), + type='many2one', relation='account_followup.followup.line', string="Latest Followup Level", store=True), + 'next_followup_level_id':fields.function(_get_next_followup_level_id, method=True, type='many2one', relation='account_followup.followup.line', string="Next Level"), + 'payment_amount_outstanding':fields.function(_get_amount, method=True, type='float', string="Amount", store=True), } res_partner() diff --git a/addons/account_followup/account_followup_customers.xml b/addons/account_followup/account_followup_customers.xml index 2204198ffd9..70a373814e3 100644 --- a/addons/account_followup/account_followup_customers.xml +++ b/addons/account_followup/account_followup_customers.xml @@ -64,6 +64,7 @@ + diff --git a/addons/account_followup/account_followup_data.xml b/addons/account_followup/account_followup_data.xml index 00da7fe3bde..1fd6ecad696 100644 --- a/addons/account_followup/account_followup_data.xml +++ b/addons/account_followup/account_followup_data.xml @@ -19,6 +19,32 @@

Hello${object.name and ' ' or ''},

We see in our books that some accounts are not settled yet:

+ + + + + + + + + + + +% for aml in object.accountmoveline_ids : + + + + + + +% endfor +
DebitCreditReference
+${aml.debit} + +${aml.credit} + +${aml.ref} +
diff --git a/addons/account_followup/test/account_followup.yml b/addons/account_followup/test/account_followup.yml index dcfdf6ef38f..dbcde7bc15b 100644 --- a/addons/account_followup/test/account_followup.yml +++ b/addons/account_followup/test/account_followup.yml @@ -10,27 +10,8 @@ - !record {model: account.followup.print, id: account_followup_print_0}: {} -#- -# I select the follow-up to send it to the partner. -# - -# !python {model: account.followup.print}: | -# self.do_continue(cr, uid, [ref("account_followup_print_0")], {"active_ids": [ref("account_followup.account_followup_print_menu")], "active_id": ref("account_followup.account_followup_print_menu"), -# }) -# - -# I select partners whom I want to send follow-ups. -# - -# !record {model: account.followup.print.all, id: account_followup_print_all_0}: -# email_body: 'Date : %(date)s\n\nDear %(partner_name)s,\n\nPlease find in attachment -# a reminder of all your unpaid invoices, for a total amount due of:\n\n%(followup_amount).2f -# %(company_currency)s\n\nThanks,\n--\n%(user_signature)s\n%(company_name)s' -# email_subject: Invoices Reminder -# partner_ids: -# - base.res_partner_12 -# partner_lang: 1 -# - -# I send a follow-up mail to partner. -# - -# !python {model: account.followup.print.all}: | -# import time -# self.do_mail(cr, uid, [ref("account_followup_print_all_0")], {"active_ids": [ref("account_followup.account_followup_print_menu")], "date": time.strftime('%Y-%m-%d'), "followup_id": ref("account_followup.demo_followup1"), "active_id": ref("account_followup.account_followup_print_menu"), -# }) +- + I will process follow-ups +- + !python {model: account.followup.print}: | + self.do_process(cr, uid, [ref("account_followup_print_0")], {"active_ids": [ref("account_followup.account_followup_print_menu")], "active_id": ref("account_followup.account_followup_print_menu"),}) \ No newline at end of file diff --git a/addons/account_followup/test/account_followup_report.yml b/addons/account_followup/test/account_followup_report.yml deleted file mode 100644 index f2ad8a5bb9f..00000000000 --- a/addons/account_followup/test/account_followup_report.yml +++ /dev/null @@ -1,10 +0,0 @@ -- - In order to test the report I print follow-up report. -- - !python {model: account.followup.print.all}: | - import time - ctx = {'form_view_ref':'account_followup.view_account_followup_print_all', 'followup_id': ref('account_followup.demo_followup1'),'date': time.strftime('%Y-%m-%d'),'model': 'account_followup.followup','active_ids':[ref('account_followup_print_all_0')], 'company_id':ref('base.main_company')} - data_dict = {'email_conf': 1} - from tools import test_reports - test_reports.try_report_action(cr, uid, 'action_account_followup_print_all', context=ctx, wiz_data=data_dict,wiz_buttons=["Print Follow-ups"], our_module='account_followup') - diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py index f926c1f1b16..dadc5994338 100644 --- a/addons/account_followup/wizard/account_followup_print.py +++ b/addons/account_followup/wizard/account_followup_print.py @@ -231,7 +231,8 @@ class account_followup_print(osv.osv_memory): "AND (a.active) "\ "AND (l.debit > 0) "\ "AND (l.company_id = %s) "\ - "ORDER BY l.date", (company_id,)) + "AND (l.blocked = False)" \ + "ORDER BY l.date", (company_id,)) #JCO!!: change l.blocked to be reviewed! move_lines = cr.fetchall() old = None fups = {} @@ -257,6 +258,8 @@ class account_followup_print(osv.osv_memory): to_update = {} for partner_id, followup_line_id, date_maturity,date, id in move_lines: + + if not partner_id: continue #part = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context) From cabac6daedc7d8fb1ee647a40b0250bac5a55ba3 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Wed, 31 Oct 2012 12:29:07 +0100 Subject: [PATCH 16/38] [WIP] Adding search filters and changing amount to overdue amount bzr revid: jco@openerp.com-20121031112907-wltw4mnm30tux1d9 --- addons/account_followup/__openerp__.py | 2 +- addons/account_followup/account_followup.py | 45 ++++++++++- .../account_followup_customers.xml | 81 ++++++++++++++++--- .../account_followup_view.xml | 3 +- .../test/account_followup.yml | 21 ++++- .../wizard/account_followup_print.py | 1 - 6 files changed, 130 insertions(+), 23 deletions(-) diff --git a/addons/account_followup/__openerp__.py b/addons/account_followup/__openerp__.py index acc4ea3ae41..6a5e144d6e0 100644 --- a/addons/account_followup/__openerp__.py +++ b/addons/account_followup/__openerp__.py @@ -61,7 +61,7 @@ Note that if you want to check the follow-up level for a given partner/account e 'demo': [], 'test': [ 'test/account_followup.yml', - #'test/account_followup_report.yml', + 'test/account_followup_report.yml', ], 'installable': True, 'auto_install': False, diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index e058977dff5..9ff6d3be372 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -161,6 +161,37 @@ class res_partner(osv.osv): def get_latest_followup_level(self): amls = self.accountmoveline_ids + def _get_next_followup_level_id_optimized(self, cr, uid, ids, name, arg, context=None): + res = {} + for partner in self.browse(cr, uid, ids): + latest_id = partner.latest_followup_level_id + if latest_id: + latest = latest_id + else: + latest = False + + delay = False + newlevel = False + if latest: #if latest exists + newlevel = latest.id + old_delay = latest.delay + else: + old_delay = False + fl_ar = self.pool.get('account_followup.followup.line').search(cr, uid, [('followup_id.company_id.id','=', partner.company_id.id)]) + + for fl_obj in self.pool.get('account_followup.followup.line').browse(cr, uid, fl_ar): + if not old_delay: + if not delay or fl_obj.delay < delay: + delay = fl_obj.delay + newlevel = fl_obj.id + else: + if (not delay and (fl_obj.delay > old_delay)) or ((fl_obj.delay < delay) and (fl_obj.delay > old_delay)): + delay = fl_obj.delay + newlevel = fl_obj.id + res[partner.id] = newlevel + #Now search one level higher + return res + def _get_next_followup_level_id(self, cr, uid, ids, name, arg, context=None): res = {} @@ -203,7 +234,8 @@ class res_partner(osv.osv): for partner in self.browse(cr, uid, ids, context): res[partner.id] = 0.0 for aml in partner.accountmoveline_ids: - res[partner.id] = res[partner.id] + aml.debit + if ((not aml.date_maturity) and (aml.date > fields.date.context_today(cr, uid, context))) or (aml.date_maturity > fields.date.context_today(cr, uid, context)): + res[partner.id] = res[partner.id] + aml.debit return res @@ -355,7 +387,12 @@ class res_partner(osv.osv): # } - + def action_done(self, cr, uid, ids, context=None): + + self.write(cr, uid, ids, {'payment_next_action_date': False, 'payment_next_action':''}, context) + + + _inherit = "res.partner" _columns = { @@ -369,8 +406,8 @@ class res_partner(osv.osv): 'latest_followup_date':fields.function(_get_latest_followup_date, method=True, type='date', string="latest followup date", store=True), 'latest_followup_level_id':fields.function(_get_latest_followup_level_id, method=True, type='many2one', relation='account_followup.followup.line', string="Latest Followup Level", store=True), - 'next_followup_level_id':fields.function(_get_next_followup_level_id, method=True, type='many2one', relation='account_followup.followup.line', string="Next Level"), - 'payment_amount_outstanding':fields.function(_get_amount, method=True, type='float', string="Amount", store=True), + 'next_followup_level_id':fields.function(_get_next_followup_level_id_optimized, method=True, type='many2one', relation='account_followup.followup.line', string="Next Level", help="Next level that will be printed"), + 'payment_amount_outstanding':fields.function(_get_amount, method=True, type='float', string="Amount Overdue", store=True), } res_partner() diff --git a/addons/account_followup/account_followup_customers.xml b/addons/account_followup/account_followup_customers.xml index 70a373814e3..a88ba06e504 100644 --- a/addons/account_followup/account_followup_customers.xml +++ b/addons/account_followup/account_followup_customers.xml @@ -10,13 +10,16 @@ form -
- + + + - - + + + + @@ -28,23 +31,37 @@ - + + + + + - - - - + + + +