diff --git a/addons/delivery/models/delivery_carrier.py b/addons/delivery/models/delivery_carrier.py
index aa4f96244d8..2fe1ea6ae78 100644
--- a/addons/delivery/models/delivery_carrier.py
+++ b/addons/delivery/models/delivery_carrier.py
@@ -308,7 +308,7 @@ class DeliveryCarrier(models.Model):
for line in order.order_line.filtered(lambda line: not line.is_delivery and not line.display_type):
total_cost += self._product_price_to_company_currency(line.product_qty, line.product_id, order.company_id)
- total_weight = order._get_estimated_weight()
+ total_weight = order._get_estimated_weight() + default_package_type.base_weight
# If max weight == 0 => division by 0. If this happens, we want to have
# more in the max weight than in the total weight, so that it only
# creates ONE package with everything.
@@ -327,7 +327,7 @@ class DeliveryCarrier(models.Model):
if picking.is_return_picking:
commodities = self._get_commodities_from_stock_move_lines(picking.move_line_ids)
- weight = picking._get_estimated_weight()
+ weight = picking._get_estimated_weight() + default_package_type.base_weight
packages.append(DeliveryPackage(commodities, weight, default_package_type, currency=picking.company_id.currency_id, picking=picking))
return packages
diff --git a/addons/delivery/models/stock_picking.py b/addons/delivery/models/stock_picking.py
index aefad9130b3..48f1bedba5e 100644
--- a/addons/delivery/models/stock_picking.py
+++ b/addons/delivery/models/stock_picking.py
@@ -11,10 +11,11 @@ from odoo.exceptions import UserError
class StockQuantPackage(models.Model):
_inherit = "stock.quant.package"
- @api.depends('quant_ids')
+ @api.depends('quant_ids', 'package_type_id')
def _compute_weight(self):
for package in self:
- weight = 0.0
+ # set initial weight to package type base weight
+ weight = package.package_type_id.base_weight or 0.0
if self.env.context.get('picking_id'):
# TODO: potential bottleneck: N packages = N queries, use groupby ?
current_picking_move_line_ids = self.env['stock.move.line'].search([
diff --git a/addons/delivery/wizard/choose_delivery_package.py b/addons/delivery/wizard/choose_delivery_package.py
index 65a9bbaa49c..7d713522931 100644
--- a/addons/delivery/wizard/choose_delivery_package.py
+++ b/addons/delivery/wizard/choose_delivery_package.py
@@ -9,25 +9,9 @@ class ChooseDeliveryPackage(models.TransientModel):
_name = 'choose.delivery.package'
_description = 'Delivery Package Selection Wizard'
- @api.model
- def default_get(self, fields_list):
- defaults = super().default_get(fields_list)
- if 'shipping_weight' in fields_list:
- picking = self.env['stock.picking'].browse(defaults.get('picking_id'))
- move_line_ids = picking.move_line_ids.filtered(lambda m:
- float_compare(m.qty_done, 0.0, precision_rounding=m.product_uom_id.rounding) > 0
- and not m.result_package_id
- )
- total_weight = 0.0
- for ml in move_line_ids:
- qty = ml.product_uom_id._compute_quantity(ml.qty_done, ml.product_id.uom_id)
- total_weight += qty * ml.product_id.weight
- defaults['shipping_weight'] = total_weight
- return defaults
-
picking_id = fields.Many2one('stock.picking', 'Picking')
delivery_package_type_id = fields.Many2one('stock.package.type', 'Delivery Package Type', check_company=True)
- shipping_weight = fields.Float('Shipping Weight')
+ shipping_weight = fields.Float('Shipping Weight', compute='_compute_shipping_weight', store=True, readonly=False)
weight_uom_name = fields.Char(string='Weight unit of measure label', compute='_compute_weight_uom_name')
company_id = fields.Many2one(related='picking_id.company_id')
@@ -37,6 +21,20 @@ class ChooseDeliveryPackage(models.TransientModel):
for package in self:
package.weight_uom_name = weight_uom_id.name
+ @api.depends('delivery_package_type_id')
+ def _compute_shipping_weight(self):
+ for rec in self:
+ move_line_ids = rec.picking_id.move_line_ids.filtered(lambda m:
+ float_compare(m.qty_done, 0.0, precision_rounding=m.product_uom_id.rounding) > 0
+ and not m.result_package_id
+ )
+ # Add package weights to shipping weight, package base weight is defined in package.type
+ total_weight = rec.delivery_package_type_id.base_weight or 0.0
+ for ml in move_line_ids:
+ qty = ml.product_uom_id._compute_quantity(ml.qty_done, ml.product_id.uom_id)
+ total_weight += qty * ml.product_id.weight
+ rec.shipping_weight = total_weight
+
@api.onchange('delivery_package_type_id', 'shipping_weight')
def _onchange_package_type_weight(self):
if self.delivery_package_type_id.max_weight and self.shipping_weight > self.delivery_package_type_id.max_weight:
diff --git a/addons/stock/models/stock_package_type.py b/addons/stock/models/stock_package_type.py
index da6ff321a46..0585c972e4a 100644
--- a/addons/stock/models/stock_package_type.py
+++ b/addons/stock/models/stock_package_type.py
@@ -19,6 +19,7 @@ class PackageType(models.Model):
height = fields.Integer('Height', help="Packaging Height")
width = fields.Integer('Width', help="Packaging Width")
packaging_length = fields.Integer('Length', help="Packaging Length")
+ base_weight = fields.Float(string='Weight', help='Weight of the package type')
max_weight = fields.Float('Max Weight', help='Maximum weight shippable in this packaging')
barcode = fields.Char('Barcode', copy=False)
weight_uom_name = fields.Char(string='Weight unit of measure label', compute='_compute_weight_uom_name', default=_get_default_weight_uom)
diff --git a/addons/stock/views/stock_package_type_view.xml b/addons/stock/views/stock_package_type_view.xml
index ed82192644a..c74e3b292fb 100644
--- a/addons/stock/views/stock_package_type_view.xml
+++ b/addons/stock/views/stock_package_type_view.xml
@@ -22,6 +22,11 @@