|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +from osv import osv, fields |
| 3 | + |
| 4 | + |
| 5 | +class WizardResendMails(osv.osv_memory): |
| 6 | + |
| 7 | + _name = 'wizard.resend.mails' |
| 8 | + |
| 9 | + def send_mails(self, cursor, uid, ids, context=None): |
| 10 | + if context is None: |
| 11 | + context = {} |
| 12 | + |
| 13 | + # Aquest mètode el que fa és posar els correus un altre cop |
| 14 | + # a la carpeta de outbox, d'aquesta forma els correus ja es |
| 15 | + # tornaran a enviar automàticament. |
| 16 | + pw_mail_obj = self.pool.get('poweremail.mailbox') |
| 17 | + pw_line_obj = self.pool.get('poweremail.campaign.line') |
| 18 | + |
| 19 | + lines_ids = self.read(cursor, uid, ids, ['lines_ids'])[0]['lines_ids'] |
| 20 | + mail_ids = [x['mail_id'][0] for x in pw_line_obj.read(cursor, uid, lines_ids, ['mail_id'])] |
| 21 | + pw_mail_obj.write(cursor, uid, mail_ids, {'folder': 'outbox'}) |
| 22 | + |
| 23 | + return {} |
| 24 | + |
| 25 | + def onchange_domain(self, cursor, uid, ids, line_ids, context=None): |
| 26 | + if context is None: |
| 27 | + context = {} |
| 28 | + |
| 29 | + pw_line_obj = self.pool.get('poweremail.campaign.line') |
| 30 | + |
| 31 | + res = {'domain': {}} |
| 32 | + pw_camp_ids = context.get('active_ids', []) |
| 33 | + pw_line_ids = pw_line_obj.search(cursor, uid, [ |
| 34 | + ('campaign_id', 'in', pw_camp_ids), |
| 35 | + ('state', '=', 'sent') |
| 36 | + ]) |
| 37 | + |
| 38 | + res['domain'].update( |
| 39 | + {'lines_ids': [('id', 'in', pw_line_ids)]} |
| 40 | + ) |
| 41 | + |
| 42 | + return res |
| 43 | + |
| 44 | + _columns = { |
| 45 | + 'state': fields.char('State', size=10), |
| 46 | + 'lines_ids': fields.many2many( |
| 47 | + 'poweremail.campaign.line', |
| 48 | + 'poweremail_lines_on_campaign', |
| 49 | + 'wizard_id', 'line_id', |
| 50 | + 'Poweremails Campaign Lines' |
| 51 | + ), |
| 52 | + } |
| 53 | + |
| 54 | + _defaults = { |
| 55 | + 'state': lambda *a: 'init', |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | +WizardResendMails() |
0 commit comments