Skip to content

Commit afce472

Browse files
committed
ODOO-236: Upgrade MultiSafepay Cloud POS module for Odoo 19 compatibility
1 parent 9256af4 commit afce472

20 files changed

Lines changed: 219 additions & 160 deletions

pos_multisafepay_cloud/README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ PoS MultiSafepay Cloud
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-%2Fmultisafepay-lightgray.png?logo=github
20-
:target: https://github.com//multisafepay/tree/18.0/pos_multisafepay_cloud
20+
:target: https://github.com//multisafepay/tree/19.0/pos_multisafepay_cloud
2121
:alt: /multisafepay
2222

2323
|badge1| |badge2| |badge3|
@@ -100,7 +100,7 @@ Bug Tracker
100100
Bugs are tracked on `GitHub Issues <https://github.com//multisafepay/issues>`_.
101101
In case of trouble, please check there if your issue has already been reported.
102102
If you spotted it first, help us to smash it by providing a detailed and welcomed
103-
`feedback <https://github.com//multisafepay/issues/new?body=module:%20pos_multisafepay_cloud%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
103+
`feedback <https://github.com//multisafepay/issues/new?body=module:%20pos_multisafepay_cloud%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
104104

105105
Do not contact contributors directly about support or help with technical issues.
106106

@@ -120,6 +120,6 @@ Contributors
120120
Maintainers
121121
-----------
122122

123-
This module is part of the `/multisafepay <https://github.com//multisafepay/tree/18.0/pos_multisafepay_cloud>`_ project on GitHub.
123+
This module is part of the `/multisafepay <https://github.com//multisafepay/tree/19.0/pos_multisafepay_cloud>`_ project on GitHub.
124124

125125
You are welcome to contribute.

pos_multisafepay_cloud/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "PoS MultiSafepay Cloud",
33
"summary": "PoC for MultiSafepay Cloud POS payments in Odoo POS",
44
"author": "MultiSafepay",
5-
"website": "https://github.com/multisafepay",
5+
"website": "https://github.com//multisafepay",
66
"license": "AGPL-3",
77
"category": "Point of Sale",
88
"version": "19.0.1.0.0",

pos_multisafepay_cloud/controllers/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# See the LICENSE.md file for more information.
44
# See the DISCLAIMER.md file for disclaimer details
55

6-
import json
76
import logging
87

98
from odoo import http
@@ -84,4 +83,3 @@ def notification(self, **kwargs):
8483
notification.get("transaction_id"),
8584
)
8685
return request.make_response("OK", status=200)
87-

pos_multisafepay_cloud/helpers/error_payload.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def format_exception(error):
5050
return f"{error_type}: {error_message}" if error_message else error_type
5151

5252
@classmethod
53-
def build(cls, payment_method_or_detail, default_detail=None, error=None, operation=None):
53+
def build(
54+
cls, payment_method_or_detail, default_detail=None, error=None, operation=None
55+
):
5456
"""Build a POS-friendly error payload for Cloud POS API failures.
5557
5658
Can be called with a simple text message:
@@ -69,12 +71,15 @@ def build(cls, payment_method_or_detail, default_detail=None, error=None, operat
6971
if default_detail is None and isinstance(payment_method_or_detail, str):
7072
final_detail = payment_method_or_detail
7173
else:
72-
final_detail = cls.humanize(
73-
payment_method_or_detail,
74-
cls.format_exception(error),
75-
default_detail,
76-
operation=operation,
77-
) or default_detail
74+
final_detail = (
75+
cls.humanize(
76+
payment_method_or_detail,
77+
cls.format_exception(error),
78+
default_detail,
79+
operation=operation,
80+
)
81+
or default_detail
82+
)
7883

7984
return {
8085
"status": "error",

pos_multisafepay_cloud/helpers/frontend_response_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# See the LICENSE.md file for more information.
44
# See the DISCLAIMER.md file for disclaimer details
55

6-
from odoo.addons.pos_multisafepay_cloud.helpers.status import _Status
76
from odoo.addons.pos_multisafepay_cloud.helpers.error_payload import (
87
_ErrorPayload,
98
)
9+
from odoo.addons.pos_multisafepay_cloud.helpers.status import _Status
1010

1111

1212
class _FrontendResponseBuilder:

pos_multisafepay_cloud/helpers/notification_payload.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from decimal import Decimal
99

1010
from odoo import _
11+
1112
from odoo.addons.pos_multisafepay_cloud.helpers.utils import (
1213
_Utils,
1314
)

pos_multisafepay_cloud/helpers/notification_validator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def validate(cls, payment_name, payment_method, raw_body=None, auth_header=None)
4141
)
4242
return False
4343

44-
return cls._validate_with_api_keys(payment_name, raw_body, auth_header, api_keys)
44+
return cls._validate_with_api_keys(
45+
payment_name, raw_body, auth_header, api_keys
46+
)
4547

4648
@staticmethod
4749
def _get_api_keys(payment_method):

pos_multisafepay_cloud/helpers/odoo_payload_builder.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# See the LICENSE.md file for more information.
44
# See the DISCLAIMER.md file for disclaimer details
55

6-
from odoo.addons.pos_multisafepay_cloud.helpers.status import _Status
76
from odoo.addons.pos_multisafepay_cloud.helpers.order_context_builder import (
87
_OrderContextBuilder,
98
)
9+
from odoo.addons.pos_multisafepay_cloud.helpers.status import _Status
1010

1111

1212
class _OdooPayloadBuilder:
@@ -42,8 +42,10 @@ def create_values(response, data, terminal_id, status):
4242
"session_id": data.get("session_id"),
4343
"terminal_id": terminal_id,
4444
"events_token": response.get("events_token") or response.get("event_token"),
45-
"remote_transaction_id": response.get("transaction_id") or response.get("order_id"),
46-
"events_stream_url": response.get("events_stream_url") or response.get("event_stream_url"),
45+
"remote_transaction_id": response.get("transaction_id")
46+
or response.get("order_id"),
47+
"events_stream_url": response.get("events_stream_url")
48+
or response.get("event_stream_url"),
4749
"last_event_id": response.get("last_event_id"),
4850
"msp_latest_response": payload,
4951
"status": status,
@@ -62,12 +64,18 @@ def write_for_cancel(payment, cancellation):
6264
:rtype: dict
6365
"""
6466
status = _Status.normalize(cancellation.get("status") or "canceled")
65-
payload = (payment.msp_latest_response or {}) | cancellation | {
66-
"status": status,
67-
"state": _Status.state(status),
68-
"order_id": payment.name,
69-
"transaction_id": cancellation.get("transaction_id") or payment.remote_transaction_id or payment.name,
70-
}
67+
payload = (
68+
(payment.msp_latest_response or {})
69+
| cancellation
70+
| {
71+
"status": status,
72+
"state": _Status.state(status),
73+
"order_id": payment.name,
74+
"transaction_id": cancellation.get("transaction_id")
75+
or payment.remote_transaction_id
76+
or payment.name,
77+
}
78+
)
7179
return {
7280
"msp_latest_response": payload,
7381
"status": status,
@@ -136,14 +144,20 @@ def write_for_notification(cls, payment, payload, method, now_string):
136144
"notification_method": method,
137145
"notification_received_at": now_string,
138146
}
139-
for key in ("last_status_refresh_error", "last_status_refresh_error_at", "last_status_refresh_error_source"):
147+
for key in (
148+
"last_status_refresh_error",
149+
"last_status_refresh_error_at",
150+
"last_status_refresh_error_source",
151+
):
140152
latest_response.pop(key, None)
141153

142154
write_vals = {
143155
"status": status,
144156
"remote_transaction_id": transaction_id,
145157
"stream_state": "done" if state != "pending" else payment.stream_state,
146-
"stream_lock_until": False if state != "pending" else payment.stream_lock_until,
158+
"stream_lock_until": False
159+
if state != "pending"
160+
else payment.stream_lock_until,
147161
}
148162

149163
cls._append_events(payload, write_vals, latest_response)
@@ -185,7 +199,9 @@ def _append_events(payload, write_vals, latest_response):
185199

186200
stream_url = payload.get("events_stream_url") or payload.get("event_stream_url")
187201
if stream_url:
188-
write_vals["events_stream_url"] = latest_response["events_stream_url"] = stream_url
202+
write_vals["events_stream_url"] = latest_response["events_stream_url"] = (
203+
stream_url
204+
)
189205

190206
@staticmethod
191207
def write_for_refresh_error(payment, remote_status, source, now_string):
@@ -238,10 +254,14 @@ def write_for_cancel_error(payment, cancellation):
238254
:return: A tuple of write values dictionary and error payload dictionary.
239255
:rtype: tuple[dict, dict]
240256
"""
241-
payload = (payment.msp_latest_response or {}) | cancellation | {
242-
"order_id": payment.name,
243-
"transaction_id": payment.remote_transaction_id or payment.name,
244-
}
257+
payload = (
258+
(payment.msp_latest_response or {})
259+
| cancellation
260+
| {
261+
"order_id": payment.name,
262+
"transaction_id": payment.remote_transaction_id or payment.name,
263+
}
264+
)
245265
write_vals = {
246266
"msp_latest_response": payload,
247267
"status": "error",

pos_multisafepay_cloud/helpers/order_context_builder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def from_payload(cls, data):
3434
"odoo_order_amount": data.get("amount") if isinstance(data, dict) else None,
3535
"odoo_shopping_cart_item_count": len(items),
3636
"odoo_shopping_cart_amount": float(cart_amount),
37-
"odoo_shopping_cart_amount_cents": _Utils.amount_to_minor_units(cart_amount),
37+
"odoo_shopping_cart_amount_cents": _Utils.amount_to_minor_units(
38+
cart_amount
39+
),
3840
"odoo_tip_amount": float(tip_amount),
3941
"odoo_tip_amount_cents": _Utils.amount_to_minor_units(tip_amount),
4042
"odoo_tip_line_count": tip_line_count,

pos_multisafepay_cloud/helpers/order_payload_builder.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from multisafepay.api.shared.customer import Customer
2121

2222
from odoo import _
23+
2324
from odoo.addons.pos_multisafepay_cloud.helpers.utils import (
2425
_Utils,
2526
)
@@ -163,9 +164,7 @@ def _apply_cart_item_taxes(cart_item, item_data):
163164
"""
164165
tax_rate_percentage = item_data.get("tax_rate_percentage")
165166
if tax_rate_percentage is not None:
166-
cart_item.add_tax_rate(
167-
_Utils.tax_rate_from_percentage(tax_rate_percentage)
168-
)
167+
cart_item.add_tax_rate(_Utils.tax_rate_from_percentage(tax_rate_percentage))
169168
elif item_data.get("tax_table_selector") is not None:
170169
cart_item.add_tax_table_selector(str(item_data.get("tax_table_selector")))
171170
else:
@@ -196,9 +195,7 @@ def customer(cls, customer_data):
196195
"zip_code": truncate_text(customer_data.get("zip_code"), 64),
197196
"city": truncate_text(customer_data.get("city"), 255),
198197
"state": truncate_text(customer_data.get("state"), 255),
199-
"country": _Utils.format_country_code(
200-
customer_data.get("country")
201-
),
198+
"country": _Utils.format_country_code(customer_data.get("country")),
202199
"phone": truncate_text(customer_data.get("phone"), 64),
203200
"email": _Utils.format_email(customer_data.get("email")),
204201
}

0 commit comments

Comments
 (0)