| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -10,7 +10,7 @@ from io import BytesIO | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import base64 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import csv | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import os,secrets | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					from datetime import datetime,timedelta,date | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					_logger = logging.getLogger(__name__) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -19,7 +19,7 @@ class opendons_operation(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    _description = 'opération marketing : mailing, emailing evenements' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    _inherit = ['mail.thread'] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    _check_company_auto = True | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    #_order = "__last_update desc" | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    #_order = "__last_update asc" | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    code=fields.Char(string='Code',required=True, translate=True,track_visibility='always') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    name=fields.Char(string='Name',required=True, translate=True,copy=False,default='campagne',track_visibility='always') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    partner_count = fields.Integer(string="count",readonly=True) | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -143,10 +143,13 @@ class opendons_operation(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if self.chanel=='mail': | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                writer.writerow(['id','key','name','firstname','title','street','street2','city','cp','country_name','operation','segment']) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            #sélections des contacts | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            res=self.select_partner_operation() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            segments=self.env['opendons.segment'].search(['&',('operation_id','=',self.id),('exclusion','=',False)]) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            #extraction des contacts sélectionnés sur chaque segment | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            q=0 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            for seg in segments: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if seg.partner_ids: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    for p in seg.partner_ids: | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -155,6 +158,7 @@ class opendons_operation(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        id=p.id | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        key=p.key | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        name=p.name | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        email=p.email | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        firstname=p.firstname if p.firstname else '' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        street=p.street if p.street else '' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        street2=p.street2 if p.street2  else '' | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -168,15 +172,23 @@ class opendons_operation(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            writer.writerow([id,key,name,firstname,email,operation,segment]) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        if self.chanel=='mail': | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            writer.writerow([id,key,name,firstname,title,street,street2,city,cp,country_name,operation,segment]) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        q=q+1 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        with open(csv_filename, 'r', encoding="utf-8") as f2: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            data = str.encode(f2.read(), 'utf-8') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					         | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        self.quantity=q | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        self.csv_export=base64.encodestring(data) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        self.document_fname='operation'+str(self.id)+'.csv' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        self.exported_date=fields.Date.context_today(self) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        #generation des exports par lot | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        for batch_export_id in self.batch_export_ids: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            batch_export_id.csv_export_batch() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					         | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					         | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					         | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        os.unlink(csv_filename) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -200,8 +212,10 @@ class opendons_operation(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					         | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        for sg in segments: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if i==1: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                mailing_domain='["&","!",'+segexcl.mailing_domain[1:-1]+','+ sg.mailing_domain[1:-1]+']' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if segexcl.mailing_domain:                 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    mailing_domain='["&","!",'+segexcl.mailing_domain[1:-1]+','+ sg.mailing_domain[1:-1]+']' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                else: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    mailing_domain='['+sg.mailing_domain[1:-1]+']' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                partners=self.env['res.partner'].search(eval(mailing_domain)) | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -229,8 +243,11 @@ class opendons_operation(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                else: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    str_domain='' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                mailing_domain='["&","!",'+str_domain+ segexcl.mailing_domain[1:-1]+',' +sg.mailing_domain[1:-1]+']' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if segexcl.mailing_domain:  | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    mailing_domain='["&","!",'+str_domain+ segexcl.mailing_domain[1:-1]+',' +sg.mailing_domain[1:-1]+']' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                else: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    mailing_domain='["&",'+sg.mailing_domain[1:-1]+']' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                partners=self.env['res.partner'].search(eval(mailing_domain)) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                #ajouts des contact à l'opération | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -241,7 +258,7 @@ class opendons_operation(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            i=i+1 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            self.exported_date=fields.Date.context_today(self, readonly=True) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            self.exported_date=datetime.now() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					         | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |