Skip to content

Commit

Permalink
pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteMeAsap committed Dec 13, 2024
1 parent d0de9d5 commit 06b8d0a
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 50 deletions.
1 change: 1 addition & 0 deletions delivery_sendcloud_official/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"category": "Operations/Inventory/Delivery",
"version": "16.0.1.1.0",
"author": "Onestein",
"website": "https://www.onestein.nl",
"license": "OPL-1",
"depends": ["web", "delivery", "base_address_extended"],
"data": [
Expand Down
4 changes: 2 additions & 2 deletions delivery_sendcloud_official/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class DeliverySendcloud(http.Controller):
@http.route(["/sendcloud/picking/download_labels"], type="http", auth="public")
def sendcloud_picking_download_labels(self, ids, **post):
picking_ids = []
for id in ids.split(","):
picking_ids.append(int(id))
for picking_id in ids.split(","):
picking_ids.append(int(picking_id))
pickings = request.env["stock.picking"].browse(picking_ids)
file_data = []
for attachment in pickings.mapped("sendcloud_parcel_ids").mapped(
Expand Down
31 changes: 16 additions & 15 deletions delivery_sendcloud_official/models/abstract_sendcloud_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import requests

from odoo import _, models
from odoo import SUPERUSER_ID, _, api, models, registry
from odoo.exceptions import UserError


Expand Down Expand Up @@ -65,12 +65,14 @@ def _do_request(self, type_request, url, data=None, auth=None, headers=None):

end_time = time.time()
response_time = end_time - start_time
with registry(self.env.cr.dbname).cursor() as new_cr:
# Create a new environment with new cursor database
new_env = api.Environment(new_cr, SUPERUSER_ID, self.env.context)
self.with_env(new_env)._log_response_in_action(
resp, type_request, url, str(data), response_time
)
err_msg = self._check_response_ok(resp)
if err_msg:
self.env.cr.rollback()
self._log_response_in_action(resp, type_request, url, str(data), response_time)
if err_msg:
self.env.cr.commit()
err_msg = err_msg + "\n" + _("Request: %s") % data
raise UserError(err_msg)
return resp
Expand All @@ -81,9 +83,8 @@ def _check_response_ok(self, resp):
ok_status = self._ok_response_status()
err_msg = ""
if resp.status_code not in ok_status:
err_msg = _("Sendcloud: %s (error code %s)") % (
resp.reason,
resp.status_code,
err_msg = _("Sendcloud: %(reason)s (error code %(status_code)s)") % (
{"reason": resp.reason, "status_code": resp.status_code}
)
if resp.status_code == 500:
err_msg += "\n" + _("Internal server error.")
Expand Down Expand Up @@ -135,12 +136,12 @@ def _log_response_in_action(

def _iterate_pagination(self, response, urlpath, list_name):
res = response.get(list_name)
next = response.get("next")
while next:
next_response = response.get("next")
while next_response:
parsed_next = urlparse(response.get("next"))
response = self._get_panel_request(urlpath + "?" + parsed_next.query)
res += response.get(list_name)
next = response.get("next")
next_response = response.get("next")
return res

def _get_request(self, url, params=None):
Expand All @@ -159,11 +160,11 @@ def _put_request(self, url, data):
return self._format_response(res)

def _format_response(self, res):
"""
The HTTP 204 No Content success status response code indicates that the
request has succeeded, but that the reply message is empty.
"""
if res.status_code == 204:
"""
The HTTP 204 No Content success status response code indicates that the
request has succeeded, but that the reply message is empty.
"""
return {}
try:
res = res.json()
Expand Down
19 changes: 13 additions & 6 deletions delivery_sendcloud_official/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,11 @@ def _sendcloud_sync_multiple_parcels(self, integration, parcel_vals_list):
if response.get("failed_parcels"):
err_msg = ""
for failed in response.get("failed_parcels"):
err_msg += _("%s:\n%s\n\n") % (
str(failed.get("parcel")),
str(failed.get("errors")),
err_msg += _("%(parcel)s:\n%(errors)s\n\n") % (
{
"parcel": str(failed.get("parcel")),
"errors": str(failed.get("errors")),
}
)
raise UserError(_("Sendcloud: %s") % err_msg)
return response["parcels"]
Expand Down Expand Up @@ -804,9 +806,14 @@ def _sync_shipment_to_sendcloud(self, err_msg, integration, vals):
str(picking.id),
str(vals),
)
err_msg += _("Order %s (shipment %s) returned an error:\n") % (
error.get("external_order_id"),
error.get("external_shipment_id"),
err_msg += _(
"Order %(external_order_id)s (shipment %"
"(external_shipment_id)s) returned an error:\n"
) % (
{
"external_order_id": error.get("external_order_id"),
"external_shipment_id": error.get("external_shipment_id"),
}
)
err_msg += str(error) + "\n\n"
return err_msg
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/** @odoo-module **/
import { WarningDialog } from '@web/core/errors/error_dialogs';
import { registry } from "@web/core/registry";
/* global sendcloud */
import { Component, onWillStart } from "@odoo/owl";
import { _lt } from "@web/core/l10n/translation";
import { loadJS } from "@web/core/assets";
import { registry } from "@web/core/registry";
import { useInputField } from "@web/views/fields/input_field_hook";
import { useService } from "@web/core/utils/hooks";
import { Component, onWillStart } from "@odoo/owl";
import { loadJS } from "@web/core/assets";
import { WarningDialog } from '@web/core/errors/error_dialogs';

export class ServicePointSelectorField extends Component {
setup() {
Expand All @@ -14,7 +15,7 @@ export class ServicePointSelectorField extends Component {
onWillStart(() => loadJS("/delivery_sendcloud_official/static/src/lib/sendcloud/api.min.js"));
}

async onClearClick(event) {
async onClearClick() {
this.props.update("");
}

Expand All @@ -34,7 +35,7 @@ export class ServicePointSelectorField extends Component {
this.props.update(JSON.stringify(servicePoint));
}

async onInputClick(ev) {
async onInputClick() {
var value = this.props.record.data.sendcloud_sp_details;
if (!value) {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ def _get_return_portal_settings(self, integration):
if response.get("error"):
error_msg = response.get("error", {}).get("message", "")
error_code = response.get("error", {}).get("code", "")
raise UserError(_("Sendcloud: error %s\n%s") % (error_code, error_msg))
raise UserError(
_("Sendcloud: error %(error_code)s\n%(error_msg)s")
% ({"error_code": error_code, "error_msg": error_msg})
)
portal = response.get("portal")
return_portal_url = "https://%s.shipping-portal.com/rp/" % portal.get("domain")
self.reasons = portal.get("reasons")
Expand Down Expand Up @@ -299,9 +302,8 @@ def _step1(self, integration):
)
if outgoing_parcel_data.get("error"):
res_error = outgoing_parcel_data.get("error")
err_msg = _("Sendcloud: %s (error code: '%s')") % (
res_error.get("message"),
res_error.get("code"),
err_msg = _("Sendcloud: %(message)s (error code: '%(code)s')") % (
{"message": res_error.get("message"), "code": res_error.get("code")}
)
self.error_message = "%s\n" % err_msg
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ def check_webhook_url(self):
except Exception as err:
self.error_message = _("Error while checking the webhook connection.\n")
self.error_message += "%s\n" % str(err)
self.error_message += _("Webhook URL: %s\n" % url)
self.error_message += _("Webhook URL: %(url)s\n") % {"url": url}
return False
if resp.status_code != 200:
err_msg = _("Webhook URL: %s (error code %s)") % (
resp.reason,
resp.status_code,
err_msg = _("Webhook URL: %(reason)s (error code %(status_code)s)") % (
{"reason": resp.reason, "status_code": resp.status_code}
)
self.error_message = _("Error while checking the webhook connection.\n")
self.error_message += "%s\n" % err_msg
Expand Down
1 change: 1 addition & 0 deletions delivery_sendcloud_official_printnode/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"category": "Operations/Inventory/Delivery",
"version": "16.0.1.1.0",
"author": "Onestein",
"website": "https://www.onestein.nl",
"license": "OPL-1",
"depends": ["delivery_sendcloud_official", "printnode_base"],
"data": ["views/stock_picking_view.xml"],
Expand Down
1 change: 1 addition & 0 deletions website_sendcloud_official/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"category": "Website/Website",
"version": "16.0.1.0.0",
"author": "Onestein",
"website": "https://www.onestein.nl",
"license": "OPL-1",
"depends": ["website_sale_delivery", "delivery_sendcloud_official"],
"data": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/** @odoo-module */

import session from 'web.session';
import publicWidget from 'web.public.widget';
import core from 'web.core';
import { _t } from 'web.core';
import { loadJS } from "@web/core/assets";
/* global sendcloud */
import concurrency from 'web.concurrency';

const { onWillStart } = owl;
const Dialog = require('web.Dialog');
import { core } from 'web.core';
import { loadJS } from "@web/core/assets";
import publicWidget from "@web/legacy/js/public/public_widget";
import { session } from "@web/session";
const QWeb = core.qweb;
const WebsiteSaleDeliverySendcloudWidget = publicWidget.registry.websiteSaleDelivery;

Expand All @@ -18,8 +14,8 @@ WebsiteSaleDeliverySendcloudWidget.include({
"click .o_website_sendcloud_address": "_onClickSendcloudAddress"
}),

init(parent, params = {}) {
this._super.apply(this, arguments);
init() {
this._super(...arguments);
this.dp = new concurrency.DropPrevious();
loadJS("/delivery_sendcloud_official/static/src/lib/sendcloud/api.min.js");
},
Expand Down Expand Up @@ -113,9 +109,9 @@ WebsiteSaleDeliverySendcloudWidget.include({
_onServicePointError: function(errors) {
const irrelevantErrors = ['Closed'];
var relevantErrors = _.difference(errors, irrelevantErrors);

if (relevantErrors.length) {
return Dialog.alert(this, relevantErrors.join("\n"));
alert(relevantErrors.join("\n"));
return;
}
},

Expand Down

0 comments on commit 06b8d0a

Please sign in to comment.