|
|
@ -50,11 +50,12 @@ class MailingContact(models.Model): |
|
|
|
|
|
|
|
@api.model |
|
|
|
def create(self, values): |
|
|
|
_logger.error('create') |
|
|
|
_logger.error(values) |
|
|
|
if not "list_ids" in values: |
|
|
|
mailing_list=self.env['mailing.list'].sudo().search([('name','=','Newsletter '+self.env.company.name)]) |
|
|
|
values['list_ids']=[(4,int(mailing_list.id))] |
|
|
|
#_logger.error('create') |
|
|
|
#_logger.error(values) |
|
|
|
# if not "list_ids" in values: |
|
|
|
# mailing_list=self.env['mailing.list'].sudo().search([('name','=','Newsletter '+self.env.company.name)]) |
|
|
|
# if mailing_list: |
|
|
|
# values['list_ids']=[(4,int(mailing_list.id))] |
|
|
|
res = super(MailingContact, self).create(values) |
|
|
|
#ajout du contact à la liste de diffusion de sendinblue |
|
|
|
|
|
|
@ -71,7 +72,7 @@ class MailingContact(models.Model): |
|
|
|
|
|
|
|
def get_info_sendinblue_contact(self): |
|
|
|
#https://developers.sendinblue.com/reference/getfolders-1 |
|
|
|
_logger.error('get_info_sendinblue_contact') |
|
|
|
#_logger.error('get_info_sendinblue_contact') |
|
|
|
f = open(SENDINBLUE_ACCOUNT_FILE) |
|
|
|
data = json.load(f) |
|
|
|
configuration = sib_api_v3_sdk.Configuration() |
|
|
@ -80,22 +81,29 @@ class MailingContact(models.Model): |
|
|
|
email = self.email |
|
|
|
|
|
|
|
try: |
|
|
|
_logger.error('get_info_sendinblue_contact -1') |
|
|
|
#_logger.error('get_info_sendinblue_contact -1') |
|
|
|
api_response = api_instance.get_contact_info(email) |
|
|
|
|
|
|
|
|
|
|
|
return (api_response) |
|
|
|
except ApiException as e: |
|
|
|
_logger.error('get_info_sendinblue_contact -2') |
|
|
|
#_logger.error('get_info_sendinblue_contact -2') |
|
|
|
#print("Exception when calling ContactsApi->get_contact_info: %s\n" % e) |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def create_sendinblue_contact(self): |
|
|
|
_logger.error('create_sendinblue_contact') |
|
|
|
_logger.error(str(self.email)+' '+ str(self.list_ids)) |
|
|
|
if self.email and self.list_ids: |
|
|
|
_logger.error('create_sendinblue_contact -1') |
|
|
|
#_logger.error('create_sendinblue_contact') |
|
|
|
#_logger.error(str(self.email)+' '+ str(self.list_ids)) |
|
|
|
if self.list_ids : |
|
|
|
llist_ids=self.list_ids |
|
|
|
else: |
|
|
|
|
|
|
|
llist_ids=self.env['mailing.list'].sudo().search([('name','=','Newsletter '+self.env.company.name)]) |
|
|
|
#llist_ids.append(mailing_list.id) |
|
|
|
|
|
|
|
if self.email and llist_ids: |
|
|
|
#_logger.error('create_sendinblue_contact -1') |
|
|
|
configuration = sib_api_v3_sdk.Configuration() |
|
|
|
#https://developers.sendinblue.com/reference/getfolders-1 |
|
|
|
f = open(SENDINBLUE_ACCOUNT_FILE) |
|
|
@ -109,8 +117,8 @@ class MailingContact(models.Model): |
|
|
|
#si le contact existe dans sendinblue, on lui rajoute la nouvelle |
|
|
|
# liste de diffusion |
|
|
|
if res: |
|
|
|
_logger.error('create_sendinblue_contact -2') |
|
|
|
for id in self.list_ids: |
|
|
|
#_logger.error('create_sendinblue_contact -2') |
|
|
|
for id in llist_ids: |
|
|
|
if id.id_sendinblue_list: |
|
|
|
if not id.id_sendinblue_list in res.list_ids: |
|
|
|
contact_emails = sib_api_v3_sdk.AddContactToList() |
|
|
@ -123,22 +131,22 @@ class MailingContact(models.Model): |
|
|
|
return True |
|
|
|
#si le contact n'existe pas dans sendinblue, on le créé |
|
|
|
else: |
|
|
|
_logger.error('create_sendinblue_contact -3') |
|
|
|
for id in self.list_ids: |
|
|
|
#_logger.error('create_sendinblue_contact -3') |
|
|
|
for id in llist_ids: |
|
|
|
list_ids.append(int(id.id_sendinblue_list)) |
|
|
|
if list_ids!=[]: |
|
|
|
create_contact = sib_api_v3_sdk.CreateContact(email=self.email, list_ids=list_ids) |
|
|
|
|
|
|
|
try: |
|
|
|
_logger.error('create_sendinblue_contact -4') |
|
|
|
#_logger.error('create_sendinblue_contact -4') |
|
|
|
api_response = api_instance.create_contact(create_contact) |
|
|
|
#raise Warning(api_response) |
|
|
|
_logger.error(api_response) |
|
|
|
#_logger.error(api_response) |
|
|
|
pprint(api_response) |
|
|
|
return True |
|
|
|
|
|
|
|
except ApiException as e: |
|
|
|
_logger.error('create_sendinblue_contact -5') |
|
|
|
_logger.error(str(e)) |
|
|
|
#_logger.error('create_sendinblue_contact -5') |
|
|
|
#_logger.error(str(e)) |
|
|
|
#raise Warning("Exception when calling ContactsApi->create_list: %s\n" % e) |
|
|
|
return False |