[FIX] stock: inventory adjustement for user
Fix the access for stock user to stock.quant. Since the inventory adjustement feature has been moved on the stock.quant. The user should be able to write on them to make their count. However we kept that a stock user can't validate an inventory nor modify quantities on product closes odoo/odoo#69006 X-original-commit: 6b8d40ec494dfbcaaef0da438692c76d0088f671 Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
This commit is contained in:
@@ -95,17 +95,17 @@ class StockQuant(models.Model):
|
||||
|
||||
# Inventory Fields
|
||||
inventory_quantity = fields.Float(
|
||||
'Counted Quantity', digits='Product Unit of Measure', groups='stock.group_stock_manager',
|
||||
'Counted Quantity', digits='Product Unit of Measure',
|
||||
help="The product's counted quantity.")
|
||||
inventory_diff_quantity = fields.Float(
|
||||
'Difference', compute='_compute_inventory_diff_quantity', store=True,
|
||||
help="Indicates the gap between the product's theoretical quantity and its counted quantity.",
|
||||
readonly=True, digits='Product Unit of Measure', groups='stock.group_stock_manager')
|
||||
readonly=True, digits='Product Unit of Measure')
|
||||
inventory_date = fields.Date(
|
||||
'Scheduled Date', compute='_compute_inventory_date', store=True, readonly=False,
|
||||
help="Next date the On Hand Quantity should be counted.")
|
||||
user_id = fields.Many2one(
|
||||
'res.users', 'Assigned To', groups='stock.group_stock_manager', help="User assigned to do product count.")
|
||||
'res.users', 'Assigned To', help="User assigned to do product count.")
|
||||
|
||||
@api.depends('quantity', 'reserved_quantity')
|
||||
def _compute_available_quantity(self):
|
||||
@@ -233,6 +233,8 @@ class StockQuant(models.Model):
|
||||
|
||||
ctx = dict(self.env.context or {})
|
||||
ctx['no_at_date'] = True
|
||||
if self.user_has_groups('stock.group_stock_user') and not self.user_has_groups('stock.group_stock_manager'):
|
||||
ctx['search_default_my_count'] = True
|
||||
action = {
|
||||
'name': _('Stock On Hand'),
|
||||
'view_mode': 'list',
|
||||
@@ -478,6 +480,8 @@ class StockQuant(models.Model):
|
||||
|
||||
def _apply_inventory(self):
|
||||
move_vals = []
|
||||
if not self.user_has_groups('stock.group_stock_manager'):
|
||||
raise UserError(_('Only a stock manager can validate an inventory adjustment.'))
|
||||
for quant in self:
|
||||
# Create and validate a move so that the quant matches its `inventory_quantity`.
|
||||
if float_compare(quant.inventory_diff_quantity, 0, precision_rounding=quant.product_uom_id.rounding) > 0:
|
||||
@@ -676,7 +680,7 @@ class StockQuant(models.Model):
|
||||
"inventory session", meaning a mode where we need to create the stock.move
|
||||
record necessary to be consistent with the `inventory_quantity` field.
|
||||
"""
|
||||
return self.env.context.get('inventory_mode') and self.user_has_groups('stock.group_stock_manager')
|
||||
return self.env.context.get('inventory_mode') and self.user_has_groups('stock.group_stock_user')
|
||||
|
||||
@api.model
|
||||
def _get_inventory_fields_create(self):
|
||||
@@ -737,7 +741,7 @@ class StockQuant(models.Model):
|
||||
self = self.with_context(default_location_id=warehouse.lot_stock_id.id, hide_location=True)
|
||||
|
||||
# If user have rights to write on quant, we set quants in inventory mode.
|
||||
if self.user_has_groups('stock.group_stock_manager'):
|
||||
if self.user_has_groups('stock.group_stock_user'):
|
||||
self = self.with_context(inventory_mode=True)
|
||||
return self
|
||||
|
||||
@@ -773,7 +777,7 @@ class StockQuant(models.Model):
|
||||
if target_action:
|
||||
action['id'] = target_action.id
|
||||
|
||||
if self._is_inventory_mode():
|
||||
if self.env.context.get('inventory_mode') and self.user_has_groups('stock.group_stock_manager'):
|
||||
action['view_id'] = self.env.ref('stock.view_stock_quant_tree_editable').id
|
||||
form_view = self.env.ref('stock.view_stock_quant_form_editable').id
|
||||
else:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from odoo.addons.stock.tests.common2 import TestStockCommon
|
||||
from odoo.tests import Form
|
||||
from odoo.exceptions import AccessError
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
@@ -83,15 +83,8 @@ class TestWarehouse(TestStockCommon):
|
||||
'new_quantity': 50.0,
|
||||
})
|
||||
# User has no right on quant, must raise an AccessError
|
||||
with self.assertRaises(AccessError):
|
||||
with self.assertRaises(UserError):
|
||||
inventory_wizard.change_product_qty()
|
||||
# Check quantity wasn't updated
|
||||
self.assertEqual(self.product_1.virtual_available, 0.0)
|
||||
self.assertEqual(self.product_1.qty_available, 0.0)
|
||||
|
||||
# Check associated quants: 0 quant expected
|
||||
quant = self.env['stock.quant'].search([('id', 'not in', self.existing_quants.ids)])
|
||||
self.assertEqual(len(quant), 0)
|
||||
|
||||
def test_basic_move(self):
|
||||
product = self.product_3.with_user(self.user_stock_manager)
|
||||
|
||||
@@ -359,7 +359,7 @@
|
||||
<field name="inventory_date" optional="show"/>
|
||||
<field name="user_id" string="User" optional="show"/>
|
||||
<field name='company_id' groups="base.group_multi_company" optional="hide"/>
|
||||
<button name="action_apply_inventory" type="object" string="Apply" class="btn btn-link" icon="fa-save" attrs="{'invisible': [('inventory_diff_quantity', '=', 0), ('inventory_quantity', '=', 0), ('quantity', '!=', 0)]}"/>
|
||||
<button name="action_apply_inventory" groups="stock.group_stock_manager" type="object" string="Apply" class="btn btn-link" icon="fa-save" attrs="{'invisible': [('inventory_diff_quantity', '=', 0), ('inventory_quantity', '=', 0), ('quantity', '!=', 0)]}"/>
|
||||
<button name="action_set_inventory_quantity" type="object" string="Set" class="btn btn-link" icon="fa-bullseye" attrs="{'invisible': ['|', '|', ('quantity', '=', 0.0), ('inventory_diff_quantity', '!=', 0), ('inventory_quantity', '!=', 0)]}"/>
|
||||
<button name="action_inventory_history" type="object" class="btn btn-link" icon="fa-history" string="History"/>
|
||||
<button name="action_set_inventory_quantity_to_zero" type="object" string="Reset" class="btn" icon="fa-times" attrs="{'invisible': [('inventory_diff_quantity', '=', 0), ('inventory_quantity', '=', 0), ('quantity', '!=', 0)]}"/>
|
||||
|
||||
Reference in New Issue
Block a user