28 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
| # -*- coding: utf-8 -*-
 | |
| from datetime import datetime
 | |
| from odoo import api, fields, models, _
 | |
| from odoo.exceptions import ValidationError
 | |
| from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
 | |
| 
 | |
| 
 | |
| class MassMailingScheduleDate(models.TransientModel):
 | |
|     _name = 'mass.mailing.schedule.date'
 | |
|     _description = 'Mass Mailing Scheduling'
 | |
| 
 | |
|     schedule_date = fields.Datetime(string='Schedule in the Future')
 | |
|     mass_mailing_id = fields.Many2one('mail.mass_mailing', required=True)
 | |
| 
 | |
|     @api.constrains('schedule_date')
 | |
|     def _check_schedule_date(self):
 | |
|         for scheduler in self:
 | |
|             if scheduler.schedule_date < fields.Datetime.now():
 | |
|                 raise ValidationError(_('Please select a date equal/or greater than the current date.'))
 | |
| 
 | |
|     def set_schedule_date(self):
 | |
|         self.ensure_one()
 | |
|         mailing = self.mass_mailing_id
 | |
|         if mailing.mailchimp_template_id:
 | |
|             schedule_date = datetime.strptime(self.schedule_date, DEFAULT_SERVER_DATETIME_FORMAT)
 | |
|             mailing.schedule_mailchimp_champaign(schedule_date)
 | |
|         self.mass_mailing_id.write({'schedule_date': self.schedule_date, 'state': 'in_queue'})
 |