mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
IMP connector_opencart Debugged through adding order history for "Shipped" with the tracking number in the comment.
This commit is contained in:
@@ -4,9 +4,6 @@
|
||||
import requests
|
||||
from urllib.parse import urlencode
|
||||
from json import loads, dumps
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Opencart:
|
||||
@@ -73,10 +70,17 @@ class Orders(Resource):
|
||||
url = self.url + ('/%s' % id)
|
||||
return self.connection.send_request(method='GET', url=url)
|
||||
|
||||
def ship(self, id, tracking):
|
||||
url = self.connection.base_url + ('trackingnumber/%s' % id)
|
||||
res = self.connection.send_request(method='PUT', url=url, body=self.get_tracking_payload(tracking))
|
||||
return self.connection.send_request(method='POST', url=url, body=self.get_status_payload('Shipped'))
|
||||
def ship(self, id, tracking, tracking_comment=None):
|
||||
def url(stem):
|
||||
return self.connection.base_url + ('%s/%s' % (stem, id))
|
||||
res = self.connection.send_request(method='PUT', url=url('trackingnumber'), body=self.get_tracking_payload(tracking))
|
||||
if tracking_comment:
|
||||
res = self.connection.send_request(method='PUT', url=url('orderhistory'), body=self.get_orderhistory_payload(
|
||||
3, # "Shipped"
|
||||
True, # Notify!
|
||||
tracking_comment,
|
||||
))
|
||||
return res
|
||||
|
||||
|
||||
def cancel(self, id):
|
||||
@@ -105,6 +109,21 @@ class Orders(Resource):
|
||||
}
|
||||
return dumps(payload)
|
||||
|
||||
def get_orderhistory_payload(self, status_id, notify, comment):
|
||||
"""
|
||||
{
|
||||
"order_status_id": "5",
|
||||
"notify": "1",
|
||||
"comment": "demo comment"
|
||||
}
|
||||
"""
|
||||
payload = {
|
||||
'order_status_id': str(status_id),
|
||||
'notify': '1' if notify else '0',
|
||||
'comment': str(comment)
|
||||
}
|
||||
return dumps(payload)
|
||||
|
||||
|
||||
class Stores(Resource):
|
||||
"""
|
||||
|
||||
@@ -139,8 +139,8 @@ class SaleOrderImportMapper(Component):
|
||||
|
||||
@mapping
|
||||
def shipping_method(self, record):
|
||||
method = record['shipping_method']
|
||||
carrier_domain = [('opencart_code', '=', method)]
|
||||
method = record['shipping_method'] or ''
|
||||
carrier_domain = [('opencart_code', '=', method.strip())]
|
||||
company = self.options.store.company_id or self.backend_record.company_id
|
||||
if company:
|
||||
carrier_domain += [
|
||||
@@ -164,14 +164,8 @@ class SaleOrderImportMapper(Component):
|
||||
|
||||
@mapping
|
||||
def total_amount(self, record):
|
||||
# lines = record['total']
|
||||
total_amount = record['total']
|
||||
total_amount_tax = 0.0
|
||||
# for l in lines:
|
||||
# item_amount, tax_amount = walk_charges(l['charges'])
|
||||
# total_amount += item_amount + tax_amount
|
||||
# total_amount_tax += tax_amount
|
||||
return {'total_amount': total_amount, 'total_amount_tax': total_amount_tax}
|
||||
return {'total_amount': total_amount}
|
||||
|
||||
|
||||
class SaleOrderImporter(Component):
|
||||
@@ -323,9 +317,9 @@ class SaleOrderImporter(Component):
|
||||
return binding
|
||||
|
||||
def _import_dependencies(self):
|
||||
record = self.opencart_record # maybe iterate over products if we need to
|
||||
self._import_addresses()
|
||||
|
||||
|
||||
class SaleOrderLineImportMapper(Component):
|
||||
|
||||
_name = 'opencart.sale.order.line.mapper'
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
# © 2019 Hibou Corp.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
import logging
|
||||
from odoo import api, models, fields
|
||||
from odoo import api, models, fields, _
|
||||
from odoo.addons.queue_job.job import job, related_action
|
||||
from odoo.addons.component.core import Component
|
||||
from odoo.addons.queue_job.exception import RetryableJobError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class OpencartStockPicking(models.Model):
|
||||
_name = 'opencart.stock.picking'
|
||||
@@ -52,7 +49,8 @@ class StockPickingAdapter(Component):
|
||||
|
||||
def create(self, id, tracking):
|
||||
api_instance = self.api_instance
|
||||
result = api_instance.orders.ship(id, tracking)
|
||||
tracking_comment = _('Order shipped with tracking number: %s') % (tracking, )
|
||||
result = api_instance.orders.ship(id, tracking, tracking_comment)
|
||||
if 'success' in result:
|
||||
return result['success']
|
||||
raise RetryableJobError('Shipping Order %s did not return an order response. (tracking: %s) %s' % (
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
# © 2019 Hibou Corp.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields
|
||||
from odoo.addons.component.core import Component
|
||||
from odoo.addons.queue_job.exception import NothingToDoJob
|
||||
from logging import getLogger
|
||||
|
||||
_logger = getLogger(__name__)
|
||||
|
||||
|
||||
class OpencartPickingExporter(Component):
|
||||
@@ -30,6 +26,7 @@ class OpencartPickingExporter(Component):
|
||||
"""
|
||||
if binding.external_id:
|
||||
return 'Already exported'
|
||||
|
||||
tracking = self._get_tracking(binding)
|
||||
if not tracking:
|
||||
raise NothingToDoJob('Cancelled: the delivery order does not contain tracking.')
|
||||
|
||||
Reference in New Issue
Block a user