diff --git a/connector_wordpress/models/ir_attachment/adapter.py b/connector_wordpress/models/ir_attachment/adapter.py index 851e451d7..429b21cd7 100644 --- a/connector_wordpress/models/ir_attachment/adapter.py +++ b/connector_wordpress/models/ir_attachment/adapter.py @@ -27,11 +27,12 @@ def create(self, data): # pylint: disable=W8106 ], limit=1, ) - alternative_binding_id = ( - self.env["wordpress.ir.attachment"] - .search([("odoo_id", "=", binded_attachments_ids.id)]) - .wordpress_idattachment + alternative_binding_id = self.env["wordpress.ir.attachment"].search( + [("odoo_id", "=", binded_attachments_ids.id)] ) if alternative_binding_id: - return {"id": alternative_binding_id} + return { + "id": alternative_binding_id.wordpress_idattachment, + "source_url": alternative_binding_id.wordpress_source_url, + } return self._exec("post", "media", data=data) diff --git a/connector_wordpress/models/ir_attachment/binder.py b/connector_wordpress/models/ir_attachment/binder.py index bb010d5bf..0d926d803 100644 --- a/connector_wordpress/models/ir_attachment/binder.py +++ b/connector_wordpress/models/ir_attachment/binder.py @@ -10,5 +10,5 @@ class WordPressIrAttachmentBinder(Component): _apply_on = "wordpress.ir.attachment" - external_id = "id" - internal_id = "wordpress_idattachment" + external_id = ["id", "source_url"] + internal_id = ["wordpress_idattachment", "wordpress_source_url"] diff --git a/connector_wordpress/models/ir_attachment/binding.py b/connector_wordpress/models/ir_attachment/binding.py index 373e26f58..f7ac68dd4 100644 --- a/connector_wordpress/models/ir_attachment/binding.py +++ b/connector_wordpress/models/ir_attachment/binding.py @@ -20,3 +20,7 @@ class WordPressIrAttachment(models.Model): string="ID Attachment", readonly=True, ) + wordpress_source_url = fields.Char( + string="Source URL", + readonly=True, + ) diff --git a/connector_wordpress/models/ir_attachment/export_mapper.py b/connector_wordpress/models/ir_attachment/export_mapper.py index 653fc583e..fd970a66e 100644 --- a/connector_wordpress/models/ir_attachment/export_mapper.py +++ b/connector_wordpress/models/ir_attachment/export_mapper.py @@ -14,19 +14,20 @@ class WordPressIrAttachmentExportMapper(Component): @mapping def name(self, record): - img_path = record._full_path(record.store_fname) + attachment_path = record._full_path(record.store_fname) + file_name = os.path.basename(attachment_path) file_type = record.mimetype.split("/")[1] # We need to concatenate the filename with the extension # because odoo does not store the extension # and wordpress needs it to recognize the file type if file_type == "octet-stream": file_type = "jpeg" - filename = os.path.basename(img_path) + "." + file_type + filename = file_name + "." + file_type headers = { "content-disposition": "attachment; filename=%s" % filename, "content-type": record.mimetype, } - data = open(img_path, "rb").read() + data = open(attachment_path, "rb").read() return { "id": record.id, "headers": headers,