From 6bdcc1760acbf8b39aabd6563eedc78a3627743a Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 25 Jul 2012 18:08:07 +0200 Subject: [PATCH] [FIX] contract: fix expired contracts reminder job to actually work The API for sending emails has changed in 6.1, use the new one. Also fix the expired contract filter to behave similarly to the "Contracts To Renew" menu inside OpenERP. bzr revid: odo@openerp.com-20120725160807-xzngv988dso9z6zj --- .../cron_account_analytic_account.py | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/addons/account_analytic_analysis/cron_account_analytic_account.py b/addons/account_analytic_analysis/cron_account_analytic_account.py index df022cbd6bd..23202ff973a 100644 --- a/addons/account_analytic_analysis/cron_account_analytic_account.py +++ b/addons/account_analytic_analysis/cron_account_analytic_account.py @@ -13,12 +13,12 @@ MAKO_TEMPLATE = u"""Hello ${user.name}, Here is a list of contracts that have to be renewed for two possible reasons: - - the end of contract date is passed - - the customer consumed more hours than expected + - the end date of the contract is passed + - the customer consumed more hours than included in the contract -Can you contact the customer in order to sell a new or renew its contract. -The contract has been set with a pending state, can you update the status -of the analytic account following this rule: +Can you contact the customer in order to sell a new or renew their contract. +The contract has been set with a pending state, please update its status +following this rule: - Set Done: if the customer does not want to renew - Set Open: if the customer purchased an extra contract @@ -39,7 +39,7 @@ Here is the list of contracts to renew: % endfor % endfor -You can use the report in the menu: Sales > Invoicing > Overdue Accounts +You can use the report in the menu: Sales > Invoicing > Contracts To Renew Regards, @@ -52,27 +52,26 @@ class analytic_account(osv.osv): def cron_account_analytic_account(self, cr, uid, context=None): domain = [ - ('name', 'not ilike', 'maintenance'), ('partner_id', '!=', False), - ('user_id', '!=', False), - ('user_id.user_email', '!=', False), ('state', 'in', ('draft', 'open')), - '|', ('date', '<', time.strftime('%Y-%m-%d')), ('date', '=', False), + '|', ('date', '<=', time.strftime('%Y-%m-%d')), + ('is_overdue_quantity', '=', True), ] - + users = {} account_ids = self.search(cr, uid, domain, context=context, order='name asc') accounts = self.browse(cr, uid, account_ids, context=context) - - users = dict() for account in accounts: - users.setdefault(account.user_id, dict()).setdefault(account.partner_id, []).append(account) - - account.write({'state' : 'pending'}, context=context) + account.write({'state' : 'pending'}) + if account.user_id: + users.setdefault(account.user_id, {}).setdefault(account.partner_id, []).append(account) + mail_message = self.pool.get('mail.message') for user, data in users.iteritems(): subject = '[OPENERP] Reporting: Analytic Accounts' body = Template(MAKO_TEMPLATE).render_unicode(user=user, partners=data) - tools.email_send('noreply@openerp.com', [user.user_email, ], subject, body) + if user.user_email: + mail_message.schedule_with_attach(cr, uid, 'noreply@openerp.com', [user.user_email], + subject, body) return True