Skip to content

Commit

Permalink
[IMP] connector_wordpress: included source_url to use in export in wo…
Browse files Browse the repository at this point in the history
…ocommerce for documents links
  • Loading branch information
KNVx committed Oct 23, 2023
1 parent ba1e4c7 commit 838d737
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
11 changes: 6 additions & 5 deletions connector_wordpress/models/ir_attachment/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 30 in connector_wordpress/models/ir_attachment/adapter.py

View check run for this annotation

Codecov / codecov/patch

connector_wordpress/models/ir_attachment/adapter.py#L30

Added line #L30 was not covered by tests
[("odoo_id", "=", binded_attachments_ids.id)]
)
if alternative_binding_id:
return {"id": alternative_binding_id}
return {

Check warning on line 34 in connector_wordpress/models/ir_attachment/adapter.py

View check run for this annotation

Codecov / codecov/patch

connector_wordpress/models/ir_attachment/adapter.py#L34

Added line #L34 was not covered by tests
"id": alternative_binding_id.wordpress_idattachment,
"source_url": alternative_binding_id.wordpress_source_url,
}
return self._exec("post", "media", data=data)

Check warning on line 38 in connector_wordpress/models/ir_attachment/adapter.py

View check run for this annotation

Codecov / codecov/patch

connector_wordpress/models/ir_attachment/adapter.py#L38

Added line #L38 was not covered by tests
4 changes: 2 additions & 2 deletions connector_wordpress/models/ir_attachment/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
4 changes: 4 additions & 0 deletions connector_wordpress/models/ir_attachment/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ class WordPressIrAttachment(models.Model):
string="ID Attachment",
readonly=True,
)
wordpress_source_url = fields.Char(
string="Source URL",
readonly=True,
)
7 changes: 4 additions & 3 deletions connector_wordpress/models/ir_attachment/export_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Check warning on line 19 in connector_wordpress/models/ir_attachment/export_mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_wordpress/models/ir_attachment/export_mapper.py#L17-L19

Added lines #L17 - L19 were not covered by tests
# 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 = {

Check warning on line 26 in connector_wordpress/models/ir_attachment/export_mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_wordpress/models/ir_attachment/export_mapper.py#L24-L26

Added lines #L24 - L26 were not covered by tests
"content-disposition": "attachment; filename=%s" % filename,
"content-type": record.mimetype,
}
data = open(img_path, "rb").read()
data = open(attachment_path, "rb").read()
return {

Check warning on line 31 in connector_wordpress/models/ir_attachment/export_mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_wordpress/models/ir_attachment/export_mapper.py#L30-L31

Added lines #L30 - L31 were not covered by tests
"id": record.id,
"headers": headers,
Expand Down

0 comments on commit 838d737

Please sign in to comment.