3 from mako.template import Template
6 import cStringIO as StringIO
12 MAKO_TEMPLATE = u"""Hello ${user.name},
14 Here is a list of contracts that have to be renewed for two
16 - the end of contract date is passed
17 - the customer consumed more hours than expected
19 Can you contact the customer in order to sell a new or renew its contract.
20 The contract has been set with a pending state, can you update the status
21 of the analytic account following this rule:
22 - Set Done: if the customer does not want to renew
23 - Set Open: if the customer purchased an extra contract
25 Here is the list of contracts to renew:
26 % for partner, accounts in partners.iteritems():
28 % for account in accounts:
29 - Name: ${account.name}
30 % if account.quantity_max != 0.0:
31 - Quantity: ${account.quantity}/${account.quantity_max} hours
33 - Dates: ${account.date_start} to ${account.date and account.date or '???'}
35 ${account.partner_id.name}, ${account.partner_id.phone}, ${account.partner_id.email}
40 You can use the report in the menu: Sales > Invoicing > Overdue Accounts
48 class analytic_account(osv.osv):
49 _inherit = 'account.analytic.account'
51 def cron_account_analytic_account(self, cr, uid, context=None):
53 ('name', 'not ilike', 'maintenance'),
54 ('partner_id', '!=', False),
55 ('user_id', '!=', False),
56 ('user_id.user_email', '!=', False),
57 ('state', 'in', ('draft', 'open')),
58 '|', ('date', '<', time.strftime('%Y-%m-%d')), ('date', '=', False),
61 account_ids = self.search(cr, uid, domain, context=context, order='name asc')
62 accounts = self.browse(cr, uid, account_ids, context=context)
65 for account in accounts:
66 users.setdefault(account.user_id, dict()).setdefault(account.partner_id, []).append(account)
68 account.write({'state' : 'pending'}, context=context)
70 for user, data in users.iteritems():
71 subject = '[OPENERP] Reporting: Analytic Accounts'
72 body = Template(MAKO_TEMPLATE).render_unicode(user=user, partners=data)
73 tools.email_send('noreply@openerp.com', [user.user_email, ], subject, body)
79 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: