addons14/base_import_async/models/base_import_import.py
def _split_file(
        self,
        model_name,
        translated_model_name,
        attachment,
        options,
        file_name="file.csv",
    ):
        """ Split a CSV attachment in smaller import jobs """
        model_obj = self.env[model_name]
        fields, data = self._read_csv_attachment(attachment, options)
        padding = len(str(len(data)))
        priority = options.get(OPT_PRIORITY, INIT_PRIORITY)
        if options.get(OPT_HAS_HEADER):
            header_offset = 1
        else:
            header_offset = 0
        chunk_size = options.get(OPT_CHUNK_SIZE) or DEFAULT_CHUNK_SIZE
        for row_from, row_to in self._extract_chunks(
            model_obj, fields, data, chunk_size
        ):
            chunk = str(priority - INIT_PRIORITY).zfill(padding)
            description = _("Import %s from file %s - #%s - lines %s to %s")
            description = description % (
                translated_model_name,
                file_name,
                chunk,
                row_from + 1 + header_offset,
                row_to + 1 + header_offset,
            )
            # create a CSV attachment and enqueue the job
            root, ext = splitext(file_name)
            attachment = self._create_csv_attachment(
                fields,
                data[row_from : row_to + 1],
                options,
                file_name=root + "-" + chunk + ext,
            )
            delayed_job = self.with_delay(
                description=description, priority=priority
            )._import_one_chunk(
                model_name=model_name, attachment=attachment, options=options
            )
            self._link_attachment_to_job(delayed_job, attachment)
            priority += 1
 Split a CSV attachment in smaller import jobs 
Split a CSV attachment in smaller import jobs
Split a CSV attachment in smaller import jobs
def _split_file(
        self,
        model_name,
        translated_model_name,
        attachment,
        options,
        file_name="file.csv",
    ):
        model_obj = self.env[model_name]
        fields, data = self._read_csv_attachment(attachment, options)
        padding = len(str(len(data)))
        priority = options.get(OPT_PRIORITY, INIT_PRIORITY)
        if options.get(OPT_HAS_HEADER):
            header_offset = 1
        else:
            header_offset = 0
        chunk_size = options.get(OPT_CHUNK_SIZE) or DEFAULT_CHUNK_SIZE
        for row_from, row_to in self._extract_chunks(
            model_obj, fields, data, chunk_size
        ):
            chunk = str(priority - INIT_PRIORITY).zfill(padding)
            description = _("Import %s from file %s - #%s - lines %s to %s")
            description = description % (
                translated_model_name,
                file_name,
                chunk,
                row_from + 1 + header_offset,
                row_to + 1 + header_offset,
            )
            root, ext = splitext(file_name)
            attachment = self._create_csv_attachment(
                fields,
                data[row_from : row_to + 1],
                options,
                file_name=root + "-" + chunk + ext,
            )
            delayed_job = self.with_delay(
                description=description, priority=priority
            )._import_one_chunk(
                model_name=model_name, attachment=attachment, options=options
            )
            self._link_attachment_to_job(delayed_job, attachment)
            priority += 1
def _split_file ( self , model_name , translated_model_name , attachment , options , file_name = "file.csv" , ) : model_obj = self . env [ model_name ] fields , data = self . _read_csv_attachment ( attachment , options ) padding = len ( str ( len ( data ) ) ) priority = options . get ( OPT_PRIORITY , INIT_PRIORITY ) if options . get ( OPT_HAS_HEADER ) : header_offset = 1 else : header_offset = 0 chunk_size = options . get ( OPT_CHUNK_SIZE ) or DEFAULT_CHUNK_SIZE for row_from , row_to in self . _extract_chunks ( model_obj , fields , data , chunk_size ) : chunk = str ( priority - INIT_PRIORITY ) . zfill ( padding ) description = _ ( "Import %s from file %s - #%s - lines %s to %s" ) description = description % ( translated_model_name , file_name , chunk , row_from + 1 + header_offset , row_to + 1 + header_offset , ) root , ext = splitext ( file_name ) attachment = self . _create_csv_attachment ( fields , data [ row_from : row_to + 1 ] , options , file_name = root + "-" + chunk + ext , ) delayed_job = self . with_delay ( description = description , priority = priority ) . _import_one_chunk ( model_name = model_name , attachment = attachment , options = options ) self . _link_attachment_to_job ( delayed_job , attachment ) priority += 1
Split a CSV attachment in smaller import jobs
Split a CSV attachment in smaller import jobs
""" Split a CSV attachment in smaller import jobs """ # create a CSV attachment and enqueue the job
self
model_name
translated_model_name
attachment
options
file_name