@@ -358,15 +358,6 @@ def enqueue(cls, func, args=None, kwargs=None,
358358 def db_record_from_uuid (env , job_uuid ):
359359 model = env ['queue.job' ].sudo ()
360360 record = model .search ([('uuid' , '=' , job_uuid )], limit = 1 )
361- if record .context :
362- try :
363- ctx = json .loads (record .context )
364- except Exception as e :
365- _logger .error ('\n \n ERROR Due to JSON CONVERSION: %s\n \n ' % e )
366- return record .with_env (env )
367- else :
368- _logger .info ("\n \n CONTEXT: %s\n \n " % ctx )
369- return record .with_context (ctx ).with_env (env )
370361 return record .with_env (env )
371362
372363 def __init__ (self , func ,
@@ -518,15 +509,13 @@ def store(self):
518509 'date_done' : False ,
519510 'eta' : False ,
520511 'identity_key' : False ,
521- 'context' : '{}' ,
522512 }
523513
524514 dt_to_string = odoo .fields .Datetime .to_string
525515 context = {}
526516 if self .keep_context :
527517 context = self .env .context .copy ()
528518 vals .update ({"context" : json .dumps (context )})
529- _logger .info ("\n \n CURRENT CONTEXT: %s\n \n " % context )
530519 if self .date_enqueued :
531520 vals ['date_enqueued' ] = dt_to_string (self .date_enqueued )
532521 if self .date_started :
@@ -543,6 +532,9 @@ def store(self):
543532 db_record .write (vals )
544533 else :
545534 date_created = dt_to_string (self .date_created )
535+ # We store the original context used at import on create
536+ ctx = self .env .context .copy () or '{}'
537+ vals .update ({'original_context' : json .dumps (ctx ) or '' })
546538 # The following values must never be modified after the
547539 # creation of the job
548540 vals .update ({'uuid' : self .uuid ,
@@ -560,27 +552,34 @@ def store(self):
560552 vals .update ({'channel' : self .channel })
561553
562554 job = self .env [self .job_model_name ].sudo ().create (vals )
563- _logger .info ('\n \n JOB: %s CONTEXT: %s' % (job , context ))
564555
565556 def db_record (self ):
566557 return self .db_record_from_uuid (self .env , self .uuid )
567558
559+ def _get_abs_context (self , original_ctx , ctx ):
560+ try :
561+ import_ctx = json .loads (original_ctx )
562+ current_ctx = json .loads (ctx )
563+ except Exception as e :
564+ _logger .error ("\n \n ERROR CONTEXT JSON CONVERSION: %s\n \n " % e )
565+ return self .env .context .copy ()
566+ else :
567+ if isinstance (import_ctx , dict ) and isinstance (current_ctx , dict ):
568+ import_ctx .update (current_ctx )
569+ return import_ctx
570+ return self .env .context .copy ()
571+
568572 def _get_record_context (self ):
569573 """
570574 Get the context to execute the job
571575 """
572- # return {}
573- company_ids = []
576+ ctx = self . _get_abs_context ( self . db_record (). original_context ,
577+ self . db_record (). context )
574578 if self .company_id :
575- company_ids = [self .company_id ]
576- context_txt = self .db_record ().context or {}
577- if isinstance (context_txt , str ):
578- context = json .loads (context_txt )
579- else :
580- context = json .loads (context_txt )
581- context .update (
582- {"job_uuid" : self .uuid , "allowed_company_ids" : company_ids })
583- return context
579+ ctx .update ({'allowed_company_ids' : [self .company_id ]})
580+ if self .uuid :
581+ ctx .update ({"job_uuid" : self .uuid })
582+ return ctx
584583
585584 @property
586585 def func (self ):
0 commit comments