mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Merge branch 'imp/11.0/delivery_planner_warehouse_carriers' into '11.0-test'
imp/11.0/delivery_planner_warehouse_carriers into 11.0-test See merge request hibou-io/hibou-odoo/suite!1151
This commit is contained in:
@@ -35,6 +35,7 @@ class FedexRequest(fedex_request.FedexRequest):
|
||||
_service_transit_days = {
|
||||
'FEDEX_2_DAY': 2,
|
||||
'FEDEX_2_DAY_AM': 2,
|
||||
'FEDEX_3_DAY_FREIGHT': 3,
|
||||
'FIRST_OVERNIGHT': 1,
|
||||
'PRIORITY_OVERNIGHT': 1,
|
||||
'STANDARD_OVERNIGHT': 1,
|
||||
@@ -195,6 +196,10 @@ class FedexRequest(fedex_request.FedexRequest):
|
||||
# Hibou Delivery Planning
|
||||
if hasattr(self.response.RateReplyDetails[0], 'DeliveryTimestamp') and self.response.RateReplyDetails[0].DeliveryTimestamp:
|
||||
formatted_response['date_delivered'] = self.response.RateReplyDetails[0].DeliveryTimestamp
|
||||
if hasattr(self.response.RateReplyDetails[0].CommitDetails[0], 'TransitTime'):
|
||||
transit_days = self.response.RateReplyDetails[0].CommitDetails[0].TransitTime
|
||||
transit_days = self._transit_days.get(transit_days, 0)
|
||||
formatted_response['transit_days'] = transit_days
|
||||
elif hasattr(self.response.RateReplyDetails[0], 'CommitDetails') and hasattr(self.response.RateReplyDetails[0].CommitDetails[0], 'CommitTimestamp'):
|
||||
formatted_response['date_delivered'] = self.response.RateReplyDetails[0].CommitDetails[0].CommitTimestamp
|
||||
formatted_response['transit_days'] = self._service_transit_days.get(self.response.RateReplyDetails[0].CommitDetails[0].ServiceType, 0)
|
||||
@@ -214,9 +219,14 @@ class FedexRequest(fedex_request.FedexRequest):
|
||||
# Hibou Delivery Planning
|
||||
if hasattr(rate_reply_detail, 'DeliveryTimestamp') and rate_reply_detail.DeliveryTimestamp:
|
||||
res['date_delivered'] = rate_reply_detail.DeliveryTimestamp
|
||||
res['transit_days'] = self._service_transit_days.get(rate_reply_detail.ServiceType, 0)
|
||||
if not res['transit_days'] and hasattr(rate_reply_detail.CommitDetails[0], 'TransitTime'):
|
||||
transit_days = rate_reply_detail.CommitDetails[0].TransitTime
|
||||
transit_days = self._transit_days.get(transit_days, 0)
|
||||
res['transit_days'] = transit_days
|
||||
elif hasattr(rate_reply_detail, 'CommitDetails') and hasattr(rate_reply_detail.CommitDetails[0], 'CommitTimestamp'):
|
||||
res['date_delivered'] = rate_reply_detail.CommitDetails[0].CommitTimestamp
|
||||
res['transit_days'] = self._service_transit_days.get(rate_reply_detail.CommitDetails[0].ServiceType, 0)
|
||||
res['transit_days'] = self._service_transit_days.get(rate_reply_detail.ServiceType, 0)
|
||||
elif hasattr(rate_reply_detail, 'CommitDetails') and hasattr(rate_reply_detail.CommitDetails[0], 'TransitTime'):
|
||||
transit_days = rate_reply_detail.CommitDetails[0].TransitTime
|
||||
transit_days = self._transit_days.get(transit_days, 0)
|
||||
|
||||
@@ -20,7 +20,7 @@ class DeliveryCarrier(models.Model):
|
||||
value = 0.0
|
||||
if order:
|
||||
if order.order_line:
|
||||
value = sum(order.order_line.filtered(lambda l: l.type != 'service').mapped('price_subtotal'))
|
||||
value = sum(order.order_line.filtered(lambda l: l.product_id.type != 'service').mapped('price_subtotal'))
|
||||
else:
|
||||
return value
|
||||
if picking:
|
||||
@@ -203,9 +203,9 @@ class DeliveryCarrier(models.Model):
|
||||
|
||||
res = []
|
||||
for carrier in self:
|
||||
carrier_packages = packages.filtered(lambda p: not p.carrier_tracking_ref and
|
||||
(not p.carrier_id or p.carrier_id == carrier) and
|
||||
p.packaging_id.package_carrier_type in (False, '', 'none', carrier.delivery_type))
|
||||
carrier_packages = packages and packages.filtered(lambda p: not p.carrier_tracking_ref and
|
||||
(not p.carrier_id or p.carrier_id == carrier) and
|
||||
p.packaging_id.package_carrier_type in (False, '', 'none', carrier.delivery_type))
|
||||
if packages and not carrier_packages:
|
||||
continue
|
||||
if hasattr(carrier, '%s_rate_shipment_multi' % self.delivery_type):
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from . import wizard
|
||||
from . import models
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
'name': 'Sale Order Planner',
|
||||
'summary': 'Plans order dates and warehouses.',
|
||||
'version': '11.0.1.0.0',
|
||||
'version': '11.0.2.0.0',
|
||||
'author': "Hibou Corp.",
|
||||
'category': 'Sale',
|
||||
'license': 'AGPL-3',
|
||||
'license': 'OPL-1',
|
||||
'complexity': 'expert',
|
||||
'images': [],
|
||||
'website': "https://hibou.io",
|
||||
@@ -37,6 +37,7 @@ on the specific method's characteristics. (e.g. Do they deliver on Saturday?)
|
||||
'views/stock.xml',
|
||||
'views/delivery.xml',
|
||||
'views/product.xml',
|
||||
'views/res_config_settings_views.xml',
|
||||
],
|
||||
'auto_install': False,
|
||||
'installable': True,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from . import sale
|
||||
from . import stock
|
||||
from . import delivery
|
||||
from . import product
|
||||
from . import planning
|
||||
from . import partner
|
||||
from . import res_config_settings
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from odoo import api, fields, models
|
||||
@@ -61,6 +63,9 @@ class DeliveryCarrier(models.Model):
|
||||
|
||||
def calculate_transit_days(self, date_planned, date_delivered):
|
||||
self.ensure_one()
|
||||
if not self.delivery_calendar_id:
|
||||
return 0
|
||||
|
||||
if isinstance(date_planned, str):
|
||||
date_planned = fields.Datetime.from_string(date_planned)
|
||||
if isinstance(date_delivered, str):
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
try:
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
|
||||
79
sale_planner/models/res_config_settings.py
Normal file
79
sale_planner/models/res_config_settings.py
Normal file
@@ -0,0 +1,79 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
def sale_planner_warehouse_ids(env, company):
|
||||
get_param = env['ir.config_parameter'].sudo().get_param
|
||||
warehouse_ids = get_param('sale.planner.warehouse_ids.%s' % (company.id, )) or []
|
||||
if warehouse_ids and isinstance(warehouse_ids, str):
|
||||
try:
|
||||
warehouse_ids = [int(i) for i in warehouse_ids.split(',')]
|
||||
except:
|
||||
warehouse_ids = []
|
||||
return warehouse_ids
|
||||
|
||||
|
||||
def sale_planner_carrier_ids(env, company):
|
||||
get_param = env['ir.config_parameter'].sudo().get_param
|
||||
carrier_ids = get_param('sale.planner.carrier_ids.%s' % (company.id, )) or []
|
||||
if carrier_ids and isinstance(carrier_ids, str):
|
||||
try:
|
||||
carrier_ids = [int(c) for c in carrier_ids.split(',')]
|
||||
except:
|
||||
carrier_ids = []
|
||||
return carrier_ids
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
sale_planner_warehouse_ids = fields.Many2many('stock.warehouse',
|
||||
string='Sale Order Planner Warehouses',
|
||||
compute='_compute_sale_planner_warehouse_ids',
|
||||
inverse='_inverse_sale_planner_warehouse_ids')
|
||||
sale_planner_carrier_ids = fields.Many2many('delivery.carrier',
|
||||
string='Sale Order Planner Carriers',
|
||||
compute='_compute_sale_planner_carrier_ids',
|
||||
inverse='_inverse_sale_planner_carrier_ids')
|
||||
|
||||
def _compute_sale_planner_warehouse_ids_ids(self):
|
||||
company = self.company_id or self.env.user.company_id
|
||||
return sale_planner_warehouse_ids(self.env, company)
|
||||
|
||||
def _compute_sale_planner_carrier_ids_ids(self):
|
||||
company = self.company_id or self.env.user.company_id
|
||||
return sale_planner_carrier_ids(self.env, company)
|
||||
|
||||
def _compute_sale_planner_warehouse_ids(self):
|
||||
for settings in self:
|
||||
warehouse_ids = settings._compute_sale_planner_warehouse_ids_ids()
|
||||
warehouses = self.env['stock.warehouse'].browse(warehouse_ids)
|
||||
settings.sale_planner_warehouse_ids = warehouses
|
||||
|
||||
def _compute_sale_planner_carrier_ids(self):
|
||||
for settings in self:
|
||||
carrier_ids = settings._compute_sale_planner_carrier_ids_ids()
|
||||
carriers = self.env['delivery.carrier'].browse(carrier_ids)
|
||||
settings.sale_planner_carrier_ids = carriers
|
||||
|
||||
def _inverse_sale_planner_warehouse_ids(self):
|
||||
set_param = self.env['ir.config_parameter'].sudo().set_param
|
||||
company_id = self.company_id.id or self.env.user.company_id.id
|
||||
for settings in self:
|
||||
warehouse_ids = ','.join(str(i) for i in settings.sale_planner_warehouse_ids.ids)
|
||||
set_param('sale.planner.warehouse_ids.%s' % (company_id, ), warehouse_ids)
|
||||
|
||||
def _inverse_sale_planner_carrier_ids(self):
|
||||
set_param = self.env['ir.config_parameter'].sudo().set_param
|
||||
company_id = self.company_id.id or self.env.user.company_id.id
|
||||
for settings in self:
|
||||
carrier_ids = ','.join(str(i) for i in settings.sale_planner_carrier_ids.ids)
|
||||
set_param('sale.planner.carrier_ids.%s' % (company_id, ), carrier_ids)
|
||||
|
||||
@api.model
|
||||
def get_values(self):
|
||||
res = super(ResConfigSettings, self).get_values()
|
||||
res['sale_planner_warehouse_ids'] = [(6, 0, self._compute_sale_planner_warehouse_ids_ids())]
|
||||
res['sale_planner_carrier_ids'] = [(6, 0, self._compute_sale_planner_carrier_ids_ids())]
|
||||
return res
|
||||
@@ -1,3 +1,5 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
@@ -7,3 +9,6 @@ class Warehouse(models.Model):
|
||||
shipping_calendar_id = fields.Many2one(
|
||||
'resource.calendar', 'Shipping Calendar',
|
||||
help="This calendar represents shipping availability from the warehouse.")
|
||||
sale_planner_carrier_ids = fields.Many2many('delivery.carrier',
|
||||
string='Sale Order Planner Base Carriers',
|
||||
help='Overrides the global carriers.')
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from . import test_planner
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests import common
|
||||
from datetime import datetime, timedelta
|
||||
from json import loads as json_decode
|
||||
|
||||
39
sale_planner/views/res_config_settings_views.xml
Normal file
39
sale_planner/views/res_config_settings_views.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||
<field name="name">res.config.settings.view.form.inherit</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="priority" eval="49"/>
|
||||
<field name="inherit_id" ref="delivery.res_config_settings_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@id='sale_ebay']" position="after">
|
||||
<h2>Sale Order Planner</h2>
|
||||
<div class="col-lg-6 col-12 o_setting_box" id="sale_planner_carriers">
|
||||
<div class="o_setting_left_pane"/>
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="sale_planner_carrier_ids" />
|
||||
<div class="text-muted">
|
||||
Add a carrier that represents the 'base rate' for a carrier's type. <br/>
|
||||
For example, you should add 1 FedEx carrier here and let us build up the
|
||||
rates for your other FedEx shipping methods.
|
||||
</div>
|
||||
<field name="sale_planner_carrier_ids" class="oe_inline" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6 col-12 o_setting_box" id="sale_planner_warehouses">
|
||||
<div class="o_setting_left_pane"/>
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="sale_planner_warehouse_ids" />
|
||||
<div class="text-muted">
|
||||
Warehouses you typically ship inventory out of that you want to
|
||||
include in the planning of sale orders.
|
||||
</div>
|
||||
<field name="sale_planner_warehouse_ids" class="oe_inline" />
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -7,6 +7,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='partner_id']" position="after">
|
||||
<field name="shipping_calendar_id" />
|
||||
<field name="sale_planner_carrier_ids" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from . import order_planner
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from math import sin, cos, sqrt, atan2, radians
|
||||
from json import dumps, loads
|
||||
from copy import deepcopy
|
||||
@@ -15,6 +17,7 @@ except ImportError:
|
||||
|
||||
from odoo import api, fields, models, tools
|
||||
from odoo.addons.base_geolocalize.models.res_partner import geo_find, geo_query_address
|
||||
from ..models.res_config_settings import sale_planner_warehouse_ids, sale_planner_carrier_ids
|
||||
|
||||
|
||||
class FakeCollection():
|
||||
@@ -294,19 +297,18 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
if domain:
|
||||
if not isinstance(domain, (list, tuple)):
|
||||
domain = tools.safe_eval(domain)
|
||||
else:
|
||||
domain = []
|
||||
|
||||
if self.env.context.get('warehouse_domain'):
|
||||
if not domain:
|
||||
domain = []
|
||||
domain.extend(self.env.context.get('warehouse_domain'))
|
||||
if domain:
|
||||
return warehouse.search(domain)
|
||||
|
||||
irconfig_parameter = self.env['ir.config_parameter'].sudo()
|
||||
if irconfig_parameter.get_param('sale.order.planner.warehouse_domain'):
|
||||
domain.extend(tools.safe_eval(irconfig_parameter.get_param('sale.order.planner.warehouse_domain')))
|
||||
# no domain, use global
|
||||
warehouse_ids = sale_planner_warehouse_ids(self.env, self.env.user.company_id)
|
||||
return warehouse.browse(warehouse_ids)
|
||||
|
||||
return warehouse.search(domain)
|
||||
|
||||
def get_shipping_carriers(self, carrier_id=None, domain=None):
|
||||
def get_shipping_carriers(self, carrier_id=None, domain=None, warehouse_id=None):
|
||||
Carrier = self.env['delivery.carrier'].sudo()
|
||||
if carrier_id:
|
||||
return Carrier.browse(carrier_id)
|
||||
@@ -314,18 +316,20 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
if domain:
|
||||
if not isinstance(domain, (list, tuple)):
|
||||
domain = tools.safe_eval(domain)
|
||||
else:
|
||||
domain = []
|
||||
|
||||
if self.env.context.get('carrier_domain'):
|
||||
# potential bug here if this is textual
|
||||
if not domain:
|
||||
domain = []
|
||||
domain.extend(self.env.context.get('carrier_domain'))
|
||||
if domain:
|
||||
return Carrier.search(domain)
|
||||
|
||||
irconfig_parameter = self.env['ir.config_parameter'].sudo()
|
||||
if irconfig_parameter.get_param('sale.order.planner.carrier_domain'):
|
||||
domain.extend(tools.safe_eval(irconfig_parameter.get_param('sale.order.planner.carrier_domain')))
|
||||
|
||||
return Carrier.search(domain)
|
||||
# no domain, use global
|
||||
if warehouse_id:
|
||||
warehouse = self.env['stock.warehouse'].sudo().browse(warehouse_id)
|
||||
if warehouse.sale_planner_carrier_ids:
|
||||
return warehouse.sale_planner_carrier_ids.sudo()
|
||||
carrier_ids = sale_planner_carrier_ids(self.env, self.env.user.company_id)
|
||||
return Carrier.browse(carrier_ids)
|
||||
|
||||
def _generate_base_option(self, order_fake, policy_group):
|
||||
policy = False
|
||||
@@ -609,6 +613,8 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
return self._find_closest_warehouse(warehouses, partner.partner_latitude, partner.partner_longitude)
|
||||
|
||||
def _find_closest_warehouse(self, warehouses, latitude, longitude):
|
||||
if not warehouses:
|
||||
return warehouses
|
||||
distances = {distance(latitude, longitude, wh.partner_id.partner_latitude, wh.partner_id.partner_longitude): wh.id for wh in warehouses}
|
||||
wh_id = distances[min(distances)]
|
||||
return warehouses.filtered(lambda wh: wh.id == wh_id)
|
||||
@@ -659,8 +665,8 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
policy = line.product_id.product_tmpl_id.get_planning_policy()
|
||||
if policy and policy.carrier_filter_id:
|
||||
domain.extend(tools.safe_eval(policy.carrier_filter_id.domain))
|
||||
carriers = self.get_shipping_carriers(base_option.get('carrier_id'), domain=domain)
|
||||
_logger.info('generate_shipping_options:: base_optoin: ' + str(base_option) + ' order_fake: ' + str(order_fake) + ' carriers: ' + str(carriers))
|
||||
carriers = self.get_shipping_carriers(base_option.get('carrier_id'), domain=domain, warehouse_id=base_option.get('warehouse_id'))
|
||||
_logger.info('generate_shipping_options:: base_option: ' + str(base_option) + ' order_fake: ' + str(order_fake) + ' carriers: ' + str(carriers))
|
||||
|
||||
if not carriers:
|
||||
return base_option
|
||||
@@ -669,9 +675,9 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
options = []
|
||||
# this locic comes from "delivery.models.sale_order.SaleOrder"
|
||||
for carrier in carriers:
|
||||
option = self._generate_shipping_carrier_option(base_option, order_fake, carrier)
|
||||
if option:
|
||||
options.append(option)
|
||||
carrier_options = self._generate_shipping_carrier_option(base_option, order_fake, carrier)
|
||||
if carrier_options:
|
||||
options += carrier_options
|
||||
if options:
|
||||
return options
|
||||
return [base_option]
|
||||
@@ -688,11 +694,11 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
continue
|
||||
order_fake.warehouse_id = warehouses.filtered(lambda wh: wh.id == wh_id)
|
||||
order_fake.order_line = FakeCollection(filter(lambda line: line.product_id.id in wh_vals['product_ids'], original_order_fake_order_line))
|
||||
wh_option = self._generate_shipping_carrier_option(wh_vals, order_fake, carrier)
|
||||
if not wh_option:
|
||||
wh_carrier_options = self._generate_shipping_carrier_option(wh_vals, order_fake, carrier)
|
||||
if not wh_carrier_options:
|
||||
has_error = True
|
||||
else:
|
||||
new_base_option['sub_options'][wh_id] = wh_option
|
||||
new_base_option['sub_options'][wh_id] = wh_carrier_options
|
||||
|
||||
if has_error:
|
||||
continue
|
||||
@@ -735,6 +741,7 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
def _generate_shipping_carrier_option(self, base_option, order_fake, carrier):
|
||||
# some carriers look at the order carrier_id
|
||||
order_fake.carrier_id = carrier
|
||||
order_fake.date_planned = base_option.get('date_planned')
|
||||
|
||||
# this logic comes from "delivery.models.sale_order.SaleOrder"
|
||||
try:
|
||||
@@ -742,7 +749,9 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
date_delivered = None
|
||||
transit_days = 0
|
||||
if carrier.delivery_type not in ['fixed', 'base_on_rule']:
|
||||
if hasattr(carrier, 'rate_shipment_date_planned'):
|
||||
if hasattr(carrier, 'rate_shipment_multi'):
|
||||
result = carrier.rate_shipment_multi(order=order_fake)
|
||||
elif hasattr(carrier, 'rate_shipment_date_planned'):
|
||||
# New API
|
||||
result = carrier.rate_shipment_date_planned(order_fake, base_option.get('date_planned'))
|
||||
if result:
|
||||
@@ -752,7 +761,8 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
elif hasattr(carrier, 'get_shipping_price_for_plan'):
|
||||
# Old API
|
||||
result = carrier.get_shipping_price_for_plan(order_fake, base_option.get('date_planned'))
|
||||
if result and isinstance(result, list):
|
||||
if result and isinstance(result, list) and not isinstance(result[0], dict):
|
||||
# this detects the above only if it isn't a list of dictionaries (aka multi-rating result)
|
||||
price_unit, transit_days, date_delivered = result[0]
|
||||
elif not result:
|
||||
rate = carrier.rate_shipment(order_fake)
|
||||
@@ -779,13 +789,32 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
if order_fake.company_id.currency_id.id != order_fake.pricelist_id.currency_id.id:
|
||||
price_unit = order_fake.company_id.currency_id.with_context(date=order_fake.date_order).compute(price_unit, order_fake.pricelist_id.currency_id)
|
||||
|
||||
final_price = float(price_unit) * (1.0 + (float(carrier.margin) / 100.0))
|
||||
option = deepcopy(base_option)
|
||||
option['carrier_id'] = carrier.id
|
||||
option['shipping_price'] = final_price
|
||||
option['requested_date'] = fields.Datetime.to_string(date_delivered) if (date_delivered and isinstance(date_delivered, datetime)) else date_delivered
|
||||
option['transit_days'] = transit_days
|
||||
return option
|
||||
if result and isinstance(result, list):
|
||||
res = []
|
||||
for rate in result:
|
||||
rate_carrier = rate.get('carrier')
|
||||
if not rate_carrier:
|
||||
continue
|
||||
price_unit = rate['price']
|
||||
date_delivered = rate.get('date_delivered')
|
||||
transit_days = rate.get('transit_days')
|
||||
|
||||
final_price = float(price_unit) * (1.0 + (float(rate_carrier.margin) / 100.0))
|
||||
option = deepcopy(base_option)
|
||||
option['carrier_id'] = rate_carrier.id
|
||||
option['shipping_price'] = final_price
|
||||
option['requested_date'] = fields.Datetime.to_string(date_delivered) if (date_delivered and isinstance(date_delivered, datetime)) else date_delivered
|
||||
option['transit_days'] = transit_days
|
||||
res.append(option)
|
||||
return res
|
||||
else:
|
||||
final_price = float(price_unit) * (1.0 + (float(carrier.margin) / 100.0))
|
||||
option = deepcopy(base_option)
|
||||
option['carrier_id'] = carrier.id
|
||||
option['shipping_price'] = final_price
|
||||
option['requested_date'] = fields.Datetime.to_string(date_delivered) if (date_delivered and isinstance(date_delivered, datetime)) else date_delivered
|
||||
option['transit_days'] = transit_days
|
||||
return option
|
||||
except Exception as e:
|
||||
_logger.info("Exception collecting carrier rates: " + str(e))
|
||||
# Want to see more?
|
||||
@@ -794,7 +823,6 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
return None
|
||||
|
||||
|
||||
|
||||
class SaleOrderPlanningOption(models.TransientModel):
|
||||
_name = 'sale.order.planning.option'
|
||||
_description = 'Order Planning Option'
|
||||
|
||||
Reference in New Issue
Block a user