1- # -*- coding: utf-8 -*-
2-
31from odoo import api , fields , models
42
53
64class MassMailingList (models .Model ):
7- _inherit = ' mail.mass_mailing.list'
5+ _inherit = " mail.mass_mailing.list"
86
97 is_member_contact = fields .Boolean (
10- default = False ,
11- help = "Populate the contact from the members" )
8+ default = False , help = "Populate the contact from the members"
9+ )
1210
1311 def compute_contacts (self , limit = 1000 ):
1412 self .remove_contacts ()
@@ -17,7 +15,7 @@ def compute_contacts(self, limit=1000):
1715 def remove_contacts (self ):
1816 if not self :
1917 return
20- sql = """
18+ sql = f """
2119 DELETE FROM mail_mass_mailing_contact_list_rel
2220 WHERE id IN (
2321 SELECT ctr.id
@@ -31,17 +29,15 @@ def remove_contacts(self):
3129 ) rp
3230 ON rp.email = ct.email
3331 WHERE rp.is_member IS FALSE
34- AND ctr.list_id in {ctr_ids}
35- )
36- """ .format (
37- ctr_ids = str (tuple (self .ids + [- 1 ]))
32+ AND ctr.list_id in { str (tuple (self .ids + [- 1 ]))}
3833 )
34+ """
3935 self ._cr .execute (sql )
4036
4137 def add_contacts (self , limit = 1000 ):
4238 if not self :
4339 return
44- sql = """
40+ sql = f """
4541 SELECT rp.id, rp.name, rp.email, rp.opt_out
4642 FROM res_partner rp
4743 LEFT JOIN mail_mass_mailing_contact ct
@@ -50,24 +46,21 @@ def add_contacts(self, limit=1000):
5046 AND rp.email NOTNULL
5147 AND rp.is_member IS TRUE
5248 LIMIT { limit }
53- """ .format (
54- limit = limit
55- )
49+ """
5650 self ._cr .execute (sql )
5751 datas = self ._cr .fetchall ()
5852 for data in datas :
5953 vals = {
60- ' name' : data [1 ],
61- ' email' : data [2 ],
62- ' is_member_contact' : True ,
63- ' subscription_list_ids' : []
54+ " name" : data [1 ],
55+ " email" : data [2 ],
56+ " is_member_contact" : True ,
57+ " subscription_list_ids" : [],
6458 }
6559 for list in self :
66- vals ['subscription_list_ids' ].append ((0 , 0 , {
67- 'list_id' : list .id ,
68- 'opt_out' : data [3 ]
69- }))
70- contact = self .env ['mail.mass_mailing.contact' ].create (vals )
60+ vals ["subscription_list_ids" ].append (
61+ (0 , 0 , {"list_id" : list .id , "opt_out" : data [3 ]})
62+ )
63+ contact = self .env ["mail.mass_mailing.contact" ].create (vals )
7164
7265 @api .model
7366 def cron_compute_contact (self , limit = 1000 ):
@@ -76,7 +69,5 @@ def cron_compute_contact(self, limit=1000):
7669 - Remove the contact which not the member anymore
7770 - Create new contact for a new member
7871 """
79- list = self .search ([
80- ('is_member_contact' , '=' , True )
81- ])
72+ list = self .search ([("is_member_contact" , "=" , True )])
8273 list .compute_contacts (limit )
0 commit comments