From cabac6daedc7d8fb1ee647a40b0250bac5a55ba3 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Wed, 31 Oct 2012 12:29:07 +0100 Subject: [PATCH] [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 ++++++++++++++++---- addons/account_followup/account_followup_view.xml | 3 +- addons/account_followup/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 acc4ea3..6a5e144 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 e058977..9ff6d3b 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 70a3738..a88ba06 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 @@ - + + + + + - - - - + + + +