Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 838d737

Browse files
committedOct 23, 2023
[IMP] connector_wordpress: included source_url to use in export in woocommerce for documents links
1 parent ba1e4c7 commit 838d737

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed
 

‎connector_wordpress/models/ir_attachment/adapter.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ def create(self, data): # pylint: disable=W8106
2727
],
2828
limit=1,
2929
)
30-
alternative_binding_id = (
31-
self.env["wordpress.ir.attachment"]
32-
.search([("odoo_id", "=", binded_attachments_ids.id)])
33-
.wordpress_idattachment
30+
alternative_binding_id = self.env["wordpress.ir.attachment"].search(
31+
[("odoo_id", "=", binded_attachments_ids.id)]
3432
)
3533
if alternative_binding_id:
36-
return {"id": alternative_binding_id}
34+
return {
35+
"id": alternative_binding_id.wordpress_idattachment,
36+
"source_url": alternative_binding_id.wordpress_source_url,
37+
}
3738
return self._exec("post", "media", data=data)

‎connector_wordpress/models/ir_attachment/binder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ class WordPressIrAttachmentBinder(Component):
1010

1111
_apply_on = "wordpress.ir.attachment"
1212

13-
external_id = "id"
14-
internal_id = "wordpress_idattachment"
13+
external_id = ["id", "source_url"]
14+
internal_id = ["wordpress_idattachment", "wordpress_source_url"]

‎connector_wordpress/models/ir_attachment/binding.py

+4
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ class WordPressIrAttachment(models.Model):
2020
string="ID Attachment",
2121
readonly=True,
2222
)
23+
wordpress_source_url = fields.Char(
24+
string="Source URL",
25+
readonly=True,
26+
)

‎connector_wordpress/models/ir_attachment/export_mapper.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ class WordPressIrAttachmentExportMapper(Component):
1414

1515
@mapping
1616
def name(self, record):
17-
img_path = record._full_path(record.store_fname)
17+
attachment_path = record._full_path(record.store_fname)
18+
file_name = os.path.basename(attachment_path)
1819
file_type = record.mimetype.split("/")[1]
1920
# We need to concatenate the filename with the extension
2021
# because odoo does not store the extension
2122
# and wordpress needs it to recognize the file type
2223
if file_type == "octet-stream":
2324
file_type = "jpeg"
24-
filename = os.path.basename(img_path) + "." + file_type
25+
filename = file_name + "." + file_type
2526
headers = {
2627
"content-disposition": "attachment; filename=%s" % filename,
2728
"content-type": record.mimetype,
2829
}
29-
data = open(img_path, "rb").read()
30+
data = open(attachment_path, "rb").read()
3031
return {
3132
"id": record.id,
3233
"headers": headers,

0 commit comments

Comments
 (0)
Please sign in to comment.