[IMP] delivery_easypost_hibou: allow easypost carriers to swap addresses

H1990
This commit is contained in:
Cedric Collins
2021-05-05 14:17:40 -05:00
committed by Jared Kipe
parent 2d4c21fdde
commit 1315ae0918
3 changed files with 28 additions and 6 deletions

View File

@@ -10,6 +10,7 @@
'delivery_hibou', 'delivery_hibou',
], ],
'data': [ 'data': [
'views/delivery_carrier_views.xml',
], ],
'demo': [ 'demo': [
], ],

View File

@@ -1,14 +1,17 @@
import requests import requests
from odoo import models, _ from odoo import fields, models, _
from odoo.exceptions import UserError from odoo.exceptions import UserError
from odoo.addons.delivery_easypost.models.easypost_request import EasypostRequest from odoo.addons.delivery_easypost.models.easypost_request import EasypostRequest
import logging
_logger = logging.getLogger(__name__)
class DeliveryCarrier(models.Model): class DeliveryCarrier(models.Model):
_inherit = 'delivery.carrier' _inherit = 'delivery.carrier'
easypost_return_method = fields.Selection([
('ep', 'EasyPost Return'),
('swap', 'Swap Addresses')
], string='Return Method', default='ep')
def easypost_send_shipping(self, pickings): def easypost_send_shipping(self, pickings):
""" It creates an easypost order and buy it with the selected rate on """ 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 delivery method or cheapest rate if it is not set. It will use the
@@ -22,9 +25,14 @@ class DeliveryCarrier(models.Model):
ep = EasypostRequest(self.sudo().easypost_production_api_key if self.prod_environment else self.sudo().easypost_test_api_key, self.log_xml) 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: for picking in pickings:
# Call Hibou delivery method to get picking type # Call Hibou delivery method to get picking type
if superself.easypost_return_method == 'ep':
is_return = superself._classify_picking(picking) in ('in', 'dropship_in',) 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, result = ep.send_shipping(self, picking.partner_id, picking.picking_type_id.warehouse_id.partner_id,
picking=picking, is_return=is_return) picking=picking, is_return=is_return)
else:
shipper = superself.get_shipper_warehouse(picking=picking)
recipient = superself.get_recipient(picking=picking)
result = ep.send_shipping(self, recipient, shipper, picking=picking)
if result.get('error_message'): if result.get('error_message'):
raise UserError(_(result['error_message'])) raise UserError(_(result['error_message']))
rate = result.get('rate') rate = result.get('rate')

View File

@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='utf-8'?>
<odoo>
<record id="view_delivery_carrier_form_inherit_delivery_easypost_hibou" model="ir.ui.view">
<field name="name">delivery.carrier.form.inherit.delivery.easypost.hibou</field>
<field name="model">delivery.carrier</field>
<field name="inherit_id" ref="delivery_easypost.view_delivery_carrier_form_inherit_delivery_easypost"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='easypost_label_file_type']" position="after">
<field name="easypost_return_method" attrs="{'required': [('delivery_type', '=', 'easypost')]}"/>
</xpath>
</field>
</record>
</odoo>