Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FW] delivery_postlogistics: multiple ports from 14.0 #905

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .oca/oca-port/blacklist/delivery_postlogistics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pull_requests": {
"OCA/delivery-carrier#377": "Migration",
"OCA/delivery-carrier#609": "Nothing to port"
}
}
21 changes: 18 additions & 3 deletions delivery_postlogistics/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import base64
from operator import attrgetter

from odoo import _, exceptions, fields, models
import lxml.html

from odoo import _, api, exceptions, fields, models

from ..postlogistics.web_service import PostlogisticsWebService

Expand Down Expand Up @@ -217,6 +219,7 @@
# Case when there is a failed label, rollback odoo data
if failed_label_results:
self._cr.rollback()
self = self.exists()

Check warning on line 222 in delivery_postlogistics/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_postlogistics/models/stock_picking.py#L222

Added line #L222 was not covered by tests

labels = self.write_tracking_number_label(success_label_results, packages)

Expand All @@ -228,10 +231,22 @@
# Commit the change to save the changes,
# This ensures the label pushed recored correctly in Odoo
self._cr.commit() # pylint: disable=invalid-commit
error_message = "\n".join(label["errors"] for label in failed_label_results)
raise exceptions.Warning(error_message)
error_message = "\n".join(

Check warning on line 234 in delivery_postlogistics/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_postlogistics/models/stock_picking.py#L234

Added line #L234 was not covered by tests
self._cleanup_error_message(label["errors"])
for label in failed_label_results
)
raise exceptions.UserError(

Check warning on line 238 in delivery_postlogistics/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_postlogistics/models/stock_picking.py#L238

Added line #L238 was not covered by tests
_("PostLogistics error:") + "\n\n" + error_message
)
return labels

@api.model
def _cleanup_error_message(self, error_message):
"""Cleanup HTML error message to be readable by users."""
texts_no_html = lxml.html.fromstring(error_message).text_content()
texts = [text for text in texts_no_html.split("\n") if text]
return "\n".join(texts)

def generate_postlogistics_shipping_labels(self, package_ids=None):
"""Add label generation for PostLogistics"""
self.ensure_one()
Expand Down
6 changes: 3 additions & 3 deletions delivery_postlogistics/postlogistics/web_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,9 @@ def get_access_token(cls, picking_carrier):

def _sanitize_string(self, value):
"""Removes disallowed chars ("|", "\", "<", ">", "’", "‘") from strings."""
if isinstance(value, str):
for char, repl in DISALLOWED_CHARS_MAPPING.items():
value = value.replace(char, repl)
value = value or ""
for char, repl in DISALLOWED_CHARS_MAPPING.items():
value = value.replace(char, repl)
return value

def generate_label(self, picking, packages):
Expand Down
7 changes: 6 additions & 1 deletion delivery_postlogistics/tests/test_sanitize_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setUpPartner(cls):
"street": "42\\|<>whateverstraße",
"street2": "42\\|<>whateverstraße",
"zip": "43123\\",
"city": "Mouais\\<>|",
"city": "<New York>",
}
)

Expand Down Expand Up @@ -58,3 +58,8 @@ def test_sanitize(self):
self.picking, packages, 1, 1
)
self.check_strings_in_dict(attributes)

def test_cleanup_error_message(self):
html_text = "<html><body><h1>TEST</h1></body></html>"
text = self.env["stock.picking"]._cleanup_error_message(html_text)
self.assertEqual(text, "TEST")
1 change: 1 addition & 0 deletions delivery_postlogistics/views/delivery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/>
<field
name="postlogistics_client_secret"
password="True"
attrs="{'required': [('delivery_type', '=', 'postlogistics')]}"
/>
<button
Expand Down
Loading