Files
odoo_source/addons/stock/wizard/stock_request_count.py
T
Nshimiyimana Séna 3aee7a8cc8 [FIX] stock: count request sets the wrong user
Steps to reproduce:
- go to Inventory > Operations > Inventory Adjustments
- Select at least one product
- Click on Request a count; A dialog box containing a form should appear
- Select a user other than the current user
- Make sure to check "Set Current Value"
- Click "Confirm"

You should see that the user you selected is not the one assigned for
the count. Instead, the count is assigned to the current user.

This is happening because currently, calling
`action_set_inventory_quantity` also sets the user as the current one
if the quantity is not already set.

opw-2924694

closes odoo/odoo#96914

X-original-commit: f2b79bc4c6198aacca33eea8905fd62c629706a1
Signed-off-by: Tiffany Chang <tic@odoo.com>
2022-07-28 05:04:57 +02:00

33 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class StockRequestCount(models.TransientModel):
_name = 'stock.request.count'
_description = 'Stock Request an Inventory Count'
inventory_date = fields.Date(
'Inventory Date', required=True,
help="Choose a date to get the inventory at that date",
default=fields.Datetime.now)
user_id = fields.Many2one('res.users', string="User")
quant_ids = fields.Many2many('stock.quant')
set_count = fields.Selection([('empty', 'Leave Empty'), ('set', 'Set Current Value')], default='empty', string='Count')
def action_request_count(self):
for count_request in self:
if count_request.set_count == 'set':
count_request.quant_ids.filtered(lambda q: not q.inventory_quantity_set).action_set_inventory_quantity()
count_request.quant_ids.with_context(inventory_mode=True).write(
count_request._get_values_to_write())
def _get_values_to_write(self):
values = {
'inventory_date': self.inventory_date,
}
if self.user_id:
values['user_id'] = self.user_id.id,
return values