[IMP] delivery,stock: added pack type weight

Base Weight field added to Package type to be added to shipping weight

Task: 2764771
Part-of: odoo/odoo#91640
This commit is contained in:
Ahmed Khalaf(ahkh)
2022-06-03 12:02:05 +02:00
committed by Ahmed Khalaf (ahkh)
parent 9c46e2ba95
commit 42714e2202
5 changed files with 26 additions and 21 deletions
+2 -2
View File
@@ -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
+3 -2
View File
@@ -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([
@@ -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:
@@ -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)
@@ -22,6 +22,11 @@
<field name="height" placeholder="Height"/>
<span><field name="length_uom_name" help="Size: Length &#215; Width &#215; Height"/></span>
</div>
<label for="base_weight"/>
<div class="o_row" name="base_weight">
<field name="base_weight"/>
<span><field name="weight_uom_name"/></span>
</div>
<label for="max_weight"/>
<div class="o_row" name="max_weight">
<field name="max_weight"/>