[IMP] delivery: set weight for shipping rate
Previously, when adding shipment to sale order, the user did not know the total weight of the order when getting rate of shipping method. This commit shows the total order weight to the user with the ability to set it to any value to get the rate with. Taskid: 2797613 Part-of: odoo/odoo#96660
This commit is contained in:
committed by
Ahmed Khalaf
parent
77dbfc9955
commit
be58a41cbb
@@ -104,7 +104,11 @@ class ProviderGrid(models.Model):
|
||||
total = (order.amount_total or 0.0) - total_delivery
|
||||
|
||||
total = self._compute_currency(order, total, 'pricelist_to_company')
|
||||
|
||||
# weight is either,
|
||||
# 1- weight chosen by user in choose.delivery.carrier wizard passed by context
|
||||
# 2- saved weight to use on sale order
|
||||
# 3- total order line weight as fallback
|
||||
weight = self.env.context.get('order_weight') or order.shipping_weight or weight
|
||||
return self._get_price_from_picking(total, weight, volume, quantity)
|
||||
|
||||
def _get_price_dict(self, total, weight, volume, quantity):
|
||||
|
||||
@@ -14,6 +14,7 @@ class SaleOrder(models.Model):
|
||||
delivery_set = fields.Boolean(compute='_compute_delivery_state')
|
||||
recompute_delivery_price = fields.Boolean('Delivery cost should be recomputed')
|
||||
is_all_service = fields.Boolean("Service Product", compute="_compute_is_service_products")
|
||||
shipping_weight = fields.Float("Shipping Weight", compute="_compute_shipping_weight", store=True, readonly=False)
|
||||
|
||||
@api.depends('order_line')
|
||||
def _compute_is_service_products(self):
|
||||
@@ -79,6 +80,7 @@ class SaleOrder(models.Model):
|
||||
'context': {
|
||||
'default_order_id': self.id,
|
||||
'default_carrier_id': carrier.id,
|
||||
'default_total_weight': self._get_estimated_weight()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,8 +145,15 @@ class SaleOrder(models.Model):
|
||||
if all(line.product_id.invoice_policy == 'delivery' and line.invoice_status == 'no' for line in order_lines):
|
||||
order.invoice_status = 'no'
|
||||
|
||||
@api.depends('order_line.product_uom_qty', 'order_line.product_uom')
|
||||
def _compute_shipping_weight(self):
|
||||
for order in self:
|
||||
order.shipping_weight = order._get_estimated_weight()
|
||||
|
||||
def _get_estimated_weight(self):
|
||||
self.ensure_one()
|
||||
if self.delivery_set:
|
||||
return self.shipping_weight
|
||||
weight = 0.0
|
||||
for order_line in self.order_line.filtered(lambda l: l.product_id.type in ['product', 'consu'] and not l.is_delivery and not l.display_type):
|
||||
weight += order_line.product_qty * order_line.product_id.weight
|
||||
|
||||
@@ -353,7 +353,11 @@
|
||||
<xpath expr="//field[@name='order_line']/tree" position="attributes">
|
||||
<attribute name="decoration-warning">recompute_delivery_price and is_delivery</attribute>
|
||||
</xpath>
|
||||
<field name="picking_policy" position="after">
|
||||
<field name="shipping_weight" readonly="True"/>
|
||||
</field>
|
||||
</data>
|
||||
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ class ChooseDeliveryCarrier(models.TransientModel):
|
||||
_name = 'choose.delivery.carrier'
|
||||
_description = 'Delivery Carrier Selection Wizard'
|
||||
|
||||
def _get_default_weight_uom(self):
|
||||
return self.env['product.template']._get_weight_uom_name_from_ir_config_parameter()
|
||||
|
||||
order_id = fields.Many2one('sale.order', required=True, ondelete="cascade")
|
||||
partner_id = fields.Many2one('res.partner', related='order_id.partner_id', required=True)
|
||||
carrier_id = fields.Many2one(
|
||||
@@ -24,8 +27,10 @@ class ChooseDeliveryCarrier(models.TransientModel):
|
||||
available_carrier_ids = fields.Many2many("delivery.carrier", compute='_compute_available_carrier', string="Available Carriers")
|
||||
invoicing_message = fields.Text(compute='_compute_invoicing_message')
|
||||
delivery_message = fields.Text(readonly=True)
|
||||
total_weight = fields.Float(string='Total Order Weight', related='order_id.shipping_weight', readonly=False)
|
||||
weight_uom_name = fields.Char(readonly=True, default=_get_default_weight_uom)
|
||||
|
||||
@api.onchange('carrier_id')
|
||||
@api.onchange('carrier_id', 'total_weight')
|
||||
def _onchange_carrier_id(self):
|
||||
self.delivery_message = False
|
||||
if self.delivery_type in ('fixed', 'base_on_rule'):
|
||||
@@ -64,7 +69,7 @@ class ChooseDeliveryCarrier(models.TransientModel):
|
||||
rec.available_carrier_ids = carriers.available_carriers(rec.order_id.partner_shipping_id) if rec.partner_id else carriers
|
||||
|
||||
def _get_shipment_rate(self):
|
||||
vals = self.carrier_id.rate_shipment(self.order_id)
|
||||
vals = self.carrier_id.with_context(order_weight=self.total_weight).rate_shipment(self.order_id)
|
||||
if vals.get('success'):
|
||||
self.delivery_message = vals.get('warning_message', False)
|
||||
self.delivery_price = vals['price']
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
<group>
|
||||
<group>
|
||||
<field name="carrier_id" domain="[('id', 'in', available_carrier_ids)]"/>
|
||||
<label for="total_weight"/>
|
||||
<div class="o_row">
|
||||
<field name="total_weight" />
|
||||
<field name="weight_uom_name" />
|
||||
</div>
|
||||
<field name="delivery_type" invisible="1"/>
|
||||
<field name="currency_id" invisible="1"/>
|
||||
<field name="order_id" invisible="1"/>
|
||||
|
||||
Reference in New Issue
Block a user