Because the barcode app bypasses the detailed operations for receipts (with default settings set), an error was being thrown when doing "put in pack" when a carrier is set (saving during the delivery package wizard) because the picking move lines are incorrectly selected. This commit adds in a check for when the wizard is accessed via the barcode app so that the error does not occur and the same behavior as when no carrier is assigned is followed. Related Enterprise PR: odoo/enterprise#9808 closes odoo/odoo#59792 Task: 2039720 X-original-commit: 945b5f6791ae890498ef9a34828eaf91dc1457e2 Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
69 lines
3.4 KiB
Python
69 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models, _
|
|
from odoo.tools.float_utils import float_compare
|
|
|
|
|
|
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_packaging_id = fields.Many2one('product.packaging', 'Delivery Packaging', check_company=True)
|
|
shipping_weight = fields.Float('Shipping Weight')
|
|
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')
|
|
|
|
@api.depends('delivery_packaging_id')
|
|
def _compute_weight_uom_name(self):
|
|
weight_uom_id = self.env['product.template']._get_weight_uom_id_from_ir_config_parameter()
|
|
for package in self:
|
|
package.weight_uom_name = weight_uom_id.name
|
|
|
|
@api.onchange('delivery_packaging_id', 'shipping_weight')
|
|
def _onchange_packaging_weight(self):
|
|
if self.delivery_packaging_id.max_weight and self.shipping_weight > self.delivery_packaging_id.max_weight:
|
|
warning_mess = {
|
|
'title': _('Package too heavy!'),
|
|
'message': _('The weight of your package is higher than the maximum weight authorized for this package type. Please choose another package type.')
|
|
}
|
|
return {'warning': warning_mess}
|
|
|
|
def action_put_in_pack(self):
|
|
picking_move_lines = self.picking_id.move_line_ids
|
|
if not self.picking_id.picking_type_id.show_reserved and not self.env.context.get('barcode_view'):
|
|
picking_move_lines = self.picking_id.move_line_nosuggest_ids
|
|
|
|
move_line_ids = picking_move_lines.filtered(lambda ml:
|
|
float_compare(ml.qty_done, 0.0, precision_rounding=ml.product_uom_id.rounding) > 0
|
|
and not ml.result_package_id
|
|
)
|
|
if not move_line_ids:
|
|
move_line_ids = picking_move_lines.filtered(lambda ml: float_compare(ml.product_uom_qty, 0.0,
|
|
precision_rounding=ml.product_uom_id.rounding) > 0 and float_compare(ml.qty_done, 0.0,
|
|
precision_rounding=ml.product_uom_id.rounding) == 0)
|
|
|
|
delivery_package = self.picking_id._put_in_pack(move_line_ids)
|
|
# write shipping weight and product_packaging on 'stock_quant_package' if needed
|
|
if self.delivery_packaging_id:
|
|
delivery_package.packaging_id = self.delivery_packaging_id
|
|
if self.shipping_weight:
|
|
delivery_package.shipping_weight = self.shipping_weight
|