|
@ -4,6 +4,8 @@ from psycopg2 import sql, DatabaseError |
|
|
from datetime import datetime |
|
|
from datetime import datetime |
|
|
from werkzeug import utils |
|
|
from werkzeug import utils |
|
|
import re |
|
|
import re |
|
|
|
|
|
import logging |
|
|
|
|
|
_logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ResPartner(models.Model): |
|
|
class ResPartner(models.Model): |
|
@ -141,6 +143,28 @@ class ResPartner(models.Model): |
|
|
|
|
|
|
|
|
raise ValidationError('Invalid email') |
|
|
raise ValidationError('Invalid email') |
|
|
|
|
|
|
|
|
|
|
|
def add_partners_to_main_sb_list(self): |
|
|
|
|
|
|
|
|
|
|
|
mailing_list=self.env['mailing.list'].sudo().search([('name','=','Newsletter '+self.env.company.name)]) |
|
|
|
|
|
|
|
|
|
|
|
partner=self.env['res.partner'].search([('email','!=',False)]) |
|
|
|
|
|
for p in partner: |
|
|
|
|
|
|
|
|
|
|
|
mailing_contact=self.env['mailing.contact'].sudo().search([('email','=',p.email)],limit=1) |
|
|
|
|
|
if not mailing_contact: |
|
|
|
|
|
vals={} |
|
|
|
|
|
vals['email']=p.email |
|
|
|
|
|
vals['name']=p.name |
|
|
|
|
|
vals['title_id']=int(p.title) |
|
|
|
|
|
vals['country_id']=int(p.country_id) |
|
|
|
|
|
vals['list_ids']=[(4,int(mailing_list.id))] |
|
|
|
|
|
mailing_contact=self.env['mailing.contact'].sudo().create(vals) |
|
|
|
|
|
_logger.error("created and added to main sb list:"+str(p.email)) |
|
|
|
|
|
else: |
|
|
|
|
|
if not mailing_list in mailing_contact.list_ids: |
|
|
|
|
|
mailing_contact.write({'list_ids':[(4,int(mailing_list.id))]}) |
|
|
|
|
|
_logger.error("updated and added to main sb list:"+str(p.email)) |
|
|
|
|
|
|
|
|
def partners_near_saint_cosme(self): |
|
|
def partners_near_saint_cosme(self): |
|
|
|
|
|
|
|
|
mailing_list=self.env['mailing.list'].sudo().search([('name','=','Habitants départements 28, 61, 72')]) |
|
|
mailing_list=self.env['mailing.list'].sudo().search([('name','=','Habitants départements 28, 61, 72')]) |
|
|