[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
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<tree editable="top" create="0">
|
||||
<field name="product_id" options="{'no_create': True, 'no_open': True}" force_save="1"/>
|
||||
<field name="quantity"/>
|
||||
<field name="uom_id" readonly="1" groups="product.group_uom"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
<field name="inherit_id" ref="stock.view_stock_return_picking_form"/>
|
||||
<field name="model">stock.return.picking</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="quantity" position="after">
|
||||
<field name="uom_id" position="after">
|
||||
<field name="to_refund"/>
|
||||
</field>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user