Skip to Content
Menú
This question has been flagged
1 Respondre
494 Vistes

Hi,
I recently incorporated documets.mixin into the CRM and sales model, which means that all new attachments will now be organized in the appropriate folders. However, there are still many attachments that were uploaded prior to this change. Is there a way to move all those existing attachments to the documents? We're talking about thousands of them.

I would appreciate any guidance on this matter.

Thanks in advance.


Avatar
Descartar
Best Answer

Hi 

make server action update manually.

find attachments of that models: 

you have already apply the "documents.mixin"

first step to get folder via _get_document_folder

second step check attachment is not available in folder:

third step If attachment not available in folder, get values "_get_document_vals"

& create the document


Or look below method 

    def _create_document(self, vals):
        """
        Implemented by bridge modules that create new documents if attachments are linked to
        their business models.

        :param vals: the create/write dictionary of ir attachment
        :return True if new documents are created
        """
        # Special case for documents
        if vals.get('res_model') == 'documents.document' and vals.get('res_id'):
            document = self.env['documents.document'].search_fetch(
                [('id', '=', vals['res_id'])], [])
            if document and not document.attachment_id and document.type == 'binary':
                document.attachment_id = self[0].id
            return False

        # Generic case for all other models
        res_model = vals.get('res_model')
        res_id = vals.get('res_id')
        model = self.env.get(res_model)
        if model is not None and res_id and issubclass(self.pool[res_model], self.pool['documents.mixin']):
            vals_list = [
                model.browse(res_id)._get_document_vals(attachment)
                for attachment in self
                if not attachment.res_field and model.browse(res_id)._check_create_documents()
            ]
            vals_list = [vals for vals in vals_list if vals]  # Remove empty values
            self.env['documents.document'].create(vals_list)
            return True
        return False


Avatar
Descartar
Related Posts Respostes Vistes Activitat
0
de des. 24
1531
1
de març 23
6742
2
d’abr. 22
4199
0
d’oct. 21
2693
2
de maig 20
12268