Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Delivery - Stock

Entity: stock.quant.package

Compute Method: _compute_weight

View 17.0 View 18.0
Inputs Method Outputs
  • id
  • uom_id
  • weight
  • package_type_id
  • package_type_id.base_weight
  • quantity
  • product_id
  • product_id.weight
- if self.env.context.get('picking_id'):
-             package_weights = defaultdict(float)
-             res_groups = self.env['stock.move.line']._read_group(
-                 [('result_package_id', 'in', self.ids), ('product_id', '!=', False), ('picking_id', '=', self.env.context['picking_id'])],
-                 ['result_package_id', 'product_id', 'product_uom_id', 'quantity'],
-                 ['__count'],
-             )
-             for result_package, product, product_uom, quantity, count in res_groups:
-                 package_weights[result_package.id] += (
-                     count
-                     * product_uom._compute_quantity(quantity, product.uom_id)
-                     * product.weight
-                 )
+ packages_weight = self.sudo()._get_weight(self.env.context.get('picking_id'))
for package in self:
-             weight = package.package_type_id.base_weight or 0.0
-             if self.env.context.get('picking_id'):
-                 package.weight = weight + package_weights[package.id]
-             else:
-                 for quant in package.quant_ids:
-                     weight += quant.quantity * quant.product_id.weight
-                 package.weight = weight
+             package.weight = packages_weight[package]
  • weight

Back to entity