mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[ADD] delivery_easypost_hibou
H1990
This commit is contained in:
committed by
Jared Kipe
parent
3b2cfc3eda
commit
2d4c21fdde
1
delivery_easypost_hibou/__init__.py
Normal file
1
delivery_easypost_hibou/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import models
|
||||||
18
delivery_easypost_hibou/__manifest__.py
Normal file
18
delivery_easypost_hibou/__manifest__.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
'name': 'Hibou EasyPost Shipping',
|
||||||
|
'version': '13.0.1.0.0',
|
||||||
|
'category': 'Stock',
|
||||||
|
'author': "Hibou Corp.",
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
'website': 'https://hibou.io/',
|
||||||
|
'depends': [
|
||||||
|
'delivery_easypost',
|
||||||
|
'delivery_hibou',
|
||||||
|
],
|
||||||
|
'data': [
|
||||||
|
],
|
||||||
|
'demo': [
|
||||||
|
],
|
||||||
|
'installable': True,
|
||||||
|
'application': False,
|
||||||
|
}
|
||||||
1
delivery_easypost_hibou/models/__init__.py
Normal file
1
delivery_easypost_hibou/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import delivery_carrier
|
||||||
63
delivery_easypost_hibou/models/delivery_carrier.py
Normal file
63
delivery_easypost_hibou/models/delivery_carrier.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import requests
|
||||||
|
from odoo import models, _
|
||||||
|
from odoo.exceptions import UserError
|
||||||
|
from odoo.addons.delivery_easypost.models.easypost_request import EasypostRequest
|
||||||
|
import logging
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class DeliveryCarrier(models.Model):
|
||||||
|
_inherit = 'delivery.carrier'
|
||||||
|
|
||||||
|
def easypost_send_shipping(self, pickings):
|
||||||
|
""" It creates an easypost order and buy it with the selected rate on
|
||||||
|
delivery method or cheapest rate if it is not set. It will use the
|
||||||
|
packages used with the put in pack functionality or a single package if
|
||||||
|
the user didn't use packages.
|
||||||
|
Once the order is purchased. It will post as message the tracking
|
||||||
|
links and the shipping labels.
|
||||||
|
"""
|
||||||
|
res = []
|
||||||
|
superself = self.sudo()
|
||||||
|
ep = EasypostRequest(self.sudo().easypost_production_api_key if self.prod_environment else self.sudo().easypost_test_api_key, self.log_xml)
|
||||||
|
for picking in pickings:
|
||||||
|
# Call Hibou delivery method to get picking type
|
||||||
|
is_return = superself._classify_picking(picking) in ('in', 'dropship_in',)
|
||||||
|
result = ep.send_shipping(self, picking.partner_id, picking.picking_type_id.warehouse_id.partner_id,
|
||||||
|
picking=picking, is_return=is_return)
|
||||||
|
if result.get('error_message'):
|
||||||
|
raise UserError(_(result['error_message']))
|
||||||
|
rate = result.get('rate')
|
||||||
|
if rate['currency'] == picking.company_id.currency_id.name:
|
||||||
|
price = float(rate['rate'])
|
||||||
|
else:
|
||||||
|
quote_currency = self.env['res.currency'].search([('name', '=', rate['currency'])], limit=1)
|
||||||
|
price = quote_currency._convert(float(rate['rate']), picking.company_id.currency_id, self.env.company, fields.Date.today())
|
||||||
|
|
||||||
|
# return tracking information
|
||||||
|
carrier_tracking_link = ""
|
||||||
|
for track_number, tracker_url in result.get('track_shipments_url').items():
|
||||||
|
carrier_tracking_link += '<a href=' + tracker_url + '>' + track_number + '</a><br/>'
|
||||||
|
|
||||||
|
carrier_tracking_ref = ' + '.join(result.get('track_shipments_url').keys())
|
||||||
|
|
||||||
|
labels = []
|
||||||
|
for track_number, label_url in result.get('track_label_data').items():
|
||||||
|
label = requests.get(label_url)
|
||||||
|
labels.append(('LabelEasypost-%s.%s' % (track_number, self.easypost_label_file_type), label.content))
|
||||||
|
|
||||||
|
logmessage = _("Shipment created into Easypost<br/>"
|
||||||
|
"<b>Tracking Numbers:</b> %s<br/>") % (carrier_tracking_link)
|
||||||
|
pickings.message_post(body=logmessage, attachments=labels)
|
||||||
|
|
||||||
|
shipping_data = {
|
||||||
|
'exact_price': price,
|
||||||
|
'tracking_number': carrier_tracking_ref,
|
||||||
|
}
|
||||||
|
res = res + [shipping_data]
|
||||||
|
# store order reference on picking
|
||||||
|
picking.ep_order_ref = result.get('id')
|
||||||
|
if picking.carrier_id.return_label_on_delivery:
|
||||||
|
self.get_return_label(picking)
|
||||||
|
return res
|
||||||
|
|
||||||
Reference in New Issue
Block a user