From 0322f6e51f41f92b3531942b0923dfe74cfcd26a Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Wed, 20 Dec 2017 10:53:49 +0100 Subject: [PATCH] [FIX] stock: return with a different uom. Usecase to reproduce: - Create a new unit of measure "Pack of 6" of UoM Categ = units - Create a new product: Coca cola can, sell in unit, purchase in packs - Create a PO, buy 1 pack of this product - Receive the pack from the delivery order - On the picking you just received, click on return -> If you validate the wizard by clicking on "return", you get 6 packs, so you multiply by 6 the amounts of what you send as the system changed the quantity but not the Uom It happens because the system compute the quanity to returns in terms of quant uom but when creating the return move it copies the origin move uom. This commit uses the quant uom on the return move and also adds the uom in the view in order to be less confusing for the end user. opw-800566 --- addons/stock/wizard/stock_picking_return.py | 6 +++++- addons/stock/wizard/stock_picking_return_views.xml | 1 + addons/stock_account/views/stock_account_views.xml | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/stock/wizard/stock_picking_return.py b/addons/stock/wizard/stock_picking_return.py index eb2c5328352..23240eb1e88 100644 --- a/addons/stock/wizard/stock_picking_return.py +++ b/addons/stock/wizard/stock_picking_return.py @@ -4,6 +4,7 @@ from odoo import api, fields, models, _ from odoo.addons import decimal_precision as dp from odoo.exceptions import UserError +from odoo.tools.float_utils import float_round class ReturnPickingLine(models.TransientModel): @@ -12,6 +13,7 @@ class ReturnPickingLine(models.TransientModel): product_id = fields.Many2one('product.product', string="Product", required=True, domain="[('id', '=', product_id)]") quantity = fields.Float("Quantity", digits=dp.get_precision('Product Unit of Measure'), required=True) + uom_id = fields.Many2one('product.uom', string='Unit of Measure', related='move_id.product_uom') wizard_id = fields.Many2one('stock.return.picking', string="Wizard") move_id = fields.Many2one('stock.move', "Move") @@ -49,7 +51,8 @@ class ReturnPicking(models.TransientModel): move_dest_exists = True quantity = move.product_qty - sum(move.move_dest_ids.filtered(lambda m: m.state in ['partially_available', 'assigned', 'done']).\ mapped('move_line_ids').mapped('product_qty')) - product_return_moves.append((0, 0, {'product_id': move.product_id.id, 'quantity': quantity, 'move_id': move.id})) + quantity = float_round(quantity, precision_rounding=move.product_uom.rounding) + product_return_moves.append((0, 0, {'product_id': move.product_id.id, 'quantity': quantity, 'move_id': move.id, 'uom_id': move.product_id.uom_id.id})) if not product_return_moves: raise UserError(_("No products to return (only lines in Done state and not fully returned yet can be returned)!")) @@ -72,6 +75,7 @@ class ReturnPicking(models.TransientModel): vals = { 'product_id': return_line.product_id.id, 'product_uom_qty': return_line.quantity, + 'product_uom': return_line.product_id.uom_id.id, 'picking_id': new_picking.id, 'state': 'draft', 'location_id': return_line.move_id.location_dest_id.id, diff --git a/addons/stock/wizard/stock_picking_return_views.xml b/addons/stock/wizard/stock_picking_return_views.xml index b7f15e73dbb..797eab283c3 100644 --- a/addons/stock/wizard/stock_picking_return_views.xml +++ b/addons/stock/wizard/stock_picking_return_views.xml @@ -20,6 +20,7 @@ + diff --git a/addons/stock_account/views/stock_account_views.xml b/addons/stock_account/views/stock_account_views.xml index 20c8f9fcd3b..e169a2b7a8d 100644 --- a/addons/stock_account/views/stock_account_views.xml +++ b/addons/stock_account/views/stock_account_views.xml @@ -43,7 +43,7 @@ stock.return.picking - +