From 2d7495b447779120cd026fe0dc7e779522c3c441 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 12 Nov 2012 18:38:57 +0100 Subject: [PATCH] [IMP] Changed problems with store bzr revid: jco@openerp.com-20121112173857-k8qws3orgd6fci6y --- addons/account_followup/account_followup.py | 133 +++++++++++++----- .../account_followup_customers.xml | 36 ++--- .../account_followup_data.xml | 14 +- .../account_followup_view.xml | 8 +- .../test/account_followup.yml | 12 +- .../wizard/account_followup_print.py | 28 ++-- 6 files changed, 133 insertions(+), 98 deletions(-) diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index 1b502edb199..0c7fed2bd66 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -22,17 +22,21 @@ from osv import fields, osv from datetime import date import time +import datetime + from tools.translate import _ class followup(osv.osv): _name = 'account_followup.followup' _description = 'Account Follow-up' + #_rec_name = 'company_id' _columns = { - 'name': fields.char('Name', size=64, required=True), + '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), @@ -41,13 +45,13 @@ class followup(osv.osv): followup() -class followup_line(osv.osv): - + + +class followup_line(osv.osv): def _get_default_template(self, cr, uid, ids, context=None): res = False templ = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_followup', 'email_template_account_followup_default') - print templ res = templ[1] return res @@ -63,7 +67,7 @@ class followup_line(osv.osv): 'send_email':fields.boolean('Send email', help="When processing, it will send an email"), 'send_letter':fields.boolean('Send letter', help="When processing, it will print a letter"), 'manual_action':fields.boolean('Manual action', help="When processing, it will set the manual action to be taken for that customer. "), - 'manual_action_note':fields.text('Action text', placeholder="e.g. Give a phonecall, check with others , ..."), + 'manual_action_note':fields.text('Action text', placeholder="e.g. Give a phone call, check with others , ..."), 'manual_action_responsible_id':fields.many2one('res.users', 'Responsible', ondelete='set null'), 'email_template_id':fields.many2one('email.template', 'Email template', ondelete='set null'), 'email_body':fields.related('email_template_id', 'body_html', type='text', string="Email Message", relation="email.template", translate="True"), @@ -153,17 +157,15 @@ class res_partner(osv.osv): def _get_latest_followup_date(self, cr, uid, ids, name, arg, context=None): res = {} - for partner in self.browse(cr, uid, ids): - amls = partner.accountmoveline_ids + for partner in self.browse(cr, uid, ids, context): + amls = partner.accountmoveline_ids res[partner.id] = max([x.followup_date for x in amls]) if len(amls) else False return res - - - + def _get_latest_followup_level_id(self, cr, uid, ids, name, arg, context=None): res = {} - for partner in self.browse(cr, uid, ids): + for partner in self.browse(cr, uid, ids, context): amls = partner.accountmoveline_ids level_id = 0 level_days = False @@ -177,23 +179,58 @@ class res_partner(osv.osv): #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_id_without_lit(self, cr, uid, ids, name, arg, context=None): - res = {} - for partner in self.browse(cr, uid, ids): + + def _get_latest(self, cr, uid, ids, names, arg, context=None): + res={} + print "change field" + for partner in self.browse(cr, uid, ids, context): amls = partner.accountmoveline_ids - level_id = 0 - level_days = False - latest_level = False - res[partner.id] = False - for accountmoveline in amls: - if (not accountmoveline.blocked) and (accountmoveline.followup_line_id != False) and (not level_days or level_days < accountmoveline.followup_line_id.delay): - level_days = accountmoveline.followup_line_id.delay - latest_level = accountmoveline.followup_line_id.id - res[partner.id] = latest_level + latest_date = False + latest_level = False + latest_level_without_lit = False + latest_days_without_lit = False + for aml in amls: + + if latest_date == False: + latest_date = aml.followup_date + latest_level = aml.followup_line_id.id + latest_days = aml.followup_line_id.delay + if not aml.blocked: + latest_level_without_lit = latest_level + latest_days_without_lit = latest_days + if latest_date and latest_level: + if aml.followup_date > latest_date: + latest_date = aml.followup_date + if aml.followup_line_id.delay > latest_days: + latest_days = aml.followup_line_id.delay + latest_level = aml.followup_line_id.id + if not aml.blocked: + latest_level_without_lit = latest_level + latest_days_without_lit = latest_days + res[partner.id] = {'latest_followup_date': latest_date, + 'latest_followup_level_id': latest_level, + 'latest_followup_level_id_without_lit': latest_level_without_lit} return res + + + +# def _get_latest_followup_level_id_without_lit(self, cr, uid, ids, name, arg, context=None): +# res = {} +# for partner in self.browse(cr, uid, ids): +# amls = partner.accountmoveline_ids +# level_id = 0 +# level_days = False +# latest_level = False +# res[partner.id] = False +# for accountmoveline in amls: +# if (not accountmoveline.blocked) and (accountmoveline.followup_line_id != False) and (not level_days or level_days < accountmoveline.followup_line_id.delay): +# level_days = accountmoveline.followup_line_id.delay +# latest_level = accountmoveline.followup_line_id.id +# res[partner.id] = latest_level +# return res - def get_latest_followup_level(self): - amls = self.accountmoveline_ids + #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): # #Apparently there is still an error in this function @@ -333,25 +370,45 @@ class res_partner(osv.osv): partnerlist.append(aml.partner_id.id) return partnerlist + def _get_other_aml_storeids(self, cr, uid, ids, context=None): + partnerlist = [] + for aml in self.pool.get("account.move.line").browse(cr, uid, ids, context): + if aml.partner_id not in partnerlist: + partnerlist.append(aml.partner_id.id) + return partnerlist _inherit = "res.partner" _columns = { 'payment_responsible_id':fields.many2one('res.users', ondelete='set null', string='Responsible', help="Responsible for making sure the action happens."), #'payment_followup_level_id':fields.many2one('account_followup.followup.line', 'Followup line'), - 'payment_note':fields.text('Payment note', help="Payment Note"), - 'payment_next_action':fields.char('Next Action', 50, help="This is the next action to be taken by the user. It will automatically be set when the action fields are empty and the partner gets a follow-up level that requires a manual action. "), #Just a note - 'payment_next_action_date':fields.date('Next Action Date', help="This is when further follow-up is needed. The date will have been set to the current date if the action fields are empty and the partner gets a follow-up level that requires a manual action. "), # next action date + 'payment_note':fields.text('Payment Note', help="Payment Note"), + 'payment_next_action':fields.char('Next Action', 50, + help="This is the next action to be taken by the user. It will automatically be set when the action fields are empty and the partner gets a follow-up level that requires a manual action. "), #Just an action + 'payment_next_action_date':fields.date('Next Action Date', + help="This is when further follow-up is needed. The date will have been set to the current date if the action fields are empty and the partner gets a follow-up level that requires a manual action. "), # next action date 'accountmoveline_ids':fields.one2many('account.move.line', 'partner_id', domain=['&', ('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 Follow-up Date", store={'account.move.line': (_get_aml_storeids, ['followup_line_id', 'followup_date'], 20)}, help="Latest date that the follow-up level of the partner was changed" ), # - 'latest_followup_level_id':fields.function(_get_latest_followup_level_id, method=True, - type='many2one', relation='account_followup.followup.line', string="Latest Follow-up Level", store={'account.move.line': (_get_aml_storeids, ['followup_line_id', 'followup_date'], 20)}, help="The maximum follow-up level"), - 'latest_followup_level_id_without_lit':fields.function(_get_latest_followup_level_id_without_lit, method=True, - type='many2one', relation='account_followup.followup.line', string="Latest Follow-up Level without litigation", help="The maximum follow-up level without taking into account the account move lines with litigation"), - 'next_followup_level_id':fields.function(_get_next_followup_level_id, method=True, type='many2one', relation='account_followup.followup.line', string="Next Level", help="The next follow-up level to come when the customer still refuses to pay", store={'account.move.line': (_get_aml_storeids, ['followup_line_id', 'followup_date'], 20)}), - 'payment_amount_overdue':fields.function(_get_amount_overdue, method=True, type='float', string="Amount Overdue", help="Amount Overdue: The amount the customer should already have paid"), + ('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')]), + 'latest_followup_date':fields.function(_get_latest, method=True, type='date', string="Latest Follow-up Date", + help="Latest date that the follow-up level of the partner was changed", + store={'account.move.line': (_get_aml_storeids, ['followup_line_id', 'followup_date'], 10)}, + multi="latest"), + 'latest_followup_level_id':fields.function(_get_latest, method=True, + type='many2one', relation='account_followup.followup.line', string="Latest Follow-up Level", + help="The maximum follow-up level", + store={'account.move.line': (_get_aml_storeids, ['followup_line_id', 'followup_date'], 10)}, + multi="latest"), + 'latest_followup_level_id_without_lit':fields.function(_get_latest, method=True, + type='many2one', relation='account_followup.followup.line', string="Latest Follow-up Level without litigation", + help="The maximum follow-up level without taking into account the account move lines with litigation", + store={'account.move.line': (_get_aml_storeids, ['followup_line_id', 'followup_date'], 10)}, + multi="latest"), + 'next_followup_level_id':fields.function(_get_next_followup_level_id, method=True, type='many2one', relation='account_followup.followup.line', + string="Next Level", help="The next follow-up level to come when the customer still refuses to pay", + store={'account.move.line': (_get_aml_storeids, ['followup_line_id', 'followup_date'], 10)}), + 'payment_amount_overdue':fields.function(_get_amount_overdue, method=True, type='float', string="Amount Overdue", + help="Amount Overdue: The amount the customer should already have paid"), } - + 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 eff96b1fbbd..c8beaa144a4 100644 --- a/addons/account_followup/account_followup_customers.xml +++ b/addons/account_followup/account_followup_customers.xml @@ -18,7 +18,6 @@ - @@ -58,10 +57,9 @@ - + - @@ -141,8 +139,8 @@ res.partner.followup.form.inherit res.partner - - + +
]]>
@@ -88,7 +88,7 @@ ${mel[aml.id]} - Followup of overdue invoices level 1 + Follow-up of overdue invoices level 1 ${user.email or ''} ${object.company_id.name} Payments Follow-up ${object.email} @@ -162,14 +162,14 @@ ${mel[aml.id]} -
Total overdue amount: ${object.payment_amount_overdue}
+
Total overdue amount: ${object.payment_amount_overdue} ${object.company_id.currency_id.name}

]]>
- Followup of overdue invoices level 2 + Follow-up of overdue invoices level 2 ${user.email or ''} ${object.company_id.name} Payments Follow-up ${object.email} @@ -241,7 +241,7 @@ ${mel[aml.id]} -
Total overdue amount: ${object.payment_amount_overdue}
+
Total overdue amount: ${object.payment_amount_overdue} ${object.company_id.currency_id.name}


@@ -323,7 +323,7 @@ ${mel[aml.id]} % endfor -
Total overdue amount: ${object.payment_amount_overdue}
+
Total overdue amount: ${object.payment_amount_overdue} ${object.company_id.currency_id.name}

]]>
diff --git a/addons/account_followup/account_followup_view.xml b/addons/account_followup/account_followup_view.xml index 91ef52ad9e1..1c90d027538 100644 --- a/addons/account_followup/account_followup_view.xml +++ b/addons/account_followup/account_followup_view.xml @@ -29,7 +29,7 @@
-
@@ -168,11 +168,11 @@
- + - + - + diff --git a/addons/account_followup/test/account_followup.yml b/addons/account_followup/test/account_followup.yml index 82c580c5ce8..b396755bc42 100644 --- a/addons/account_followup/test/account_followup.yml +++ b/addons/account_followup/test/account_followup.yml @@ -27,14 +27,4 @@ Unnecessary test of invoice - !assert {model: account.invoice, id: account.demo_invoice_0}: - - check_total == 14.0 -- - Test latest followup level changed Python -- - !python {model: res.partner, id: base.res_partner_12}: | - assert(latest_followup_level_id == ref("demo_followup_line1")) -- - Test latest followup level changed -- - !assert {model: res.partner, id: base.res_partner_12} : - - latest_followup_level_id == ref("demo_followup_line1") \ No newline at end of file + - check_total == 14.0 \ No newline at end of file diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py index a178c99a4a4..81483ca374d 100644 --- a/addons/account_followup/wizard/account_followup_print.py +++ b/addons/account_followup/wizard/account_followup_print.py @@ -142,12 +142,13 @@ class account_followup_print(osv.osv_memory): #update the followupo level on account.move.line for id in to_update.keys(): if to_update[id]['partner_id'] in partner_list: - cr.execute( - "UPDATE account_move_line "\ - "SET followup_line_id=%s, followup_date=%s "\ - "WHERE id=%s", - (to_update[id]['level'], - date, int(id),)) + self.pool.get('account.move.line').write(cr, uid, [int(id)], {'followup_line_id': to_update[id]['level'], 'followup_date': date}) +# 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) @@ -250,6 +251,8 @@ class account_followup_print(osv.osv_memory): return {'partner_ids': partner_list, 'to_update': to_update} + +#OLD FUNCTION! def do_print(self, cr, uid, ids, context=None): if context is None: context = {} @@ -261,12 +264,13 @@ class account_followup_print(osv.osv_memory): if not data['test_print']: 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),)) + self.pool.get('account.move.line').write(cr, uid, [int(id)], {'followup_line_id': to_update[id], 'followup_date': date}) +# cr.execute( +# "UPDATE account_move_line "\ +# "SET followup_line_id=%s, followup_date=%s "\ +# "WHERE id=%s", +# (to_update[id]['level'], +# date, int(id),)) data.update({'date': context['date']}) datas = { 'ids': [],