Skip to content
Permalink
Browse files

[FIX]stock_account: stock manager group not inherit account bill group

The inheritance of account billing group gives stock managers the access
to account module.
This commit is to remove this inheritance. When we need to access
account.move model, check if the user is a stock manager. If so, use
sudo() to get the access.

PR #
Task 2062611
  • Loading branch information
yhu-odoo committed Jan 9, 2020
1 parent a72006d commit 7b26611fd9f3cd2ea9177256a0c6f0dc594b33fe
@@ -55,9 +55,12 @@ def write(self, vals):
if product_template.valuation == 'real_time':
move_vals_list += Product._svl_replenish_stock_am(in_stock_valuation_layers)

# Only manager are allowed to create account moves
if move_vals_list and not self.env.user.has_group('stock.group_stock_manager'):
raise UserError(_("The action leads to the creation of a journal entry, for which you don't have the access rights."))
# Create the account moves.
if move_vals_list:
account_moves = self.env['account.move'].create(move_vals_list)
account_moves = self.env['account.move'].sudo().create(move_vals_list)
account_moves.post()
return res

@@ -180,7 +183,7 @@ def _change_standard_price(self, new_price, counterpart_account_id=False):
"""
# Handle stock valuation layers.

if self.valuation == 'real_time' and not self.env['account.move'].check_access_rights('create', raise_exception=False):
if self.valuation == 'real_time' and not self.env.user.has_group('stock.group_stock_manager'):
raise UserError(_("You cannot update the cost of a product in automated valuation as it leads to the creation of a journal entry, for which you don't have the access rights."))

svl_vals_list = []
@@ -738,8 +741,11 @@ def write(self, vals):
if product_category.property_valuation == 'real_time':
move_vals_list += Product._svl_replenish_stock_am(in_stock_valuation_layers)

# Only manager are allowed to create account moves
if move_vals_list and not self.env.user.has_group('stock.group_stock_manager'):
raise UserError(_("The action leads to the creation of a journal entry, for which you don't have the access rights."))
# Create the account moves.
if move_vals_list:
account_moves = self.env['account.move'].create(move_vals_list)
account_moves = self.env['account.move'].sudo().create(move_vals_list)
account_moves.post()
return res
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
<record id="stock.group_stock_manager" model="res.groups">
<field name="implied_ids" eval="[(4, ref('account.group_account_invoice'))]"/>
</record>

<record model="ir.rule" id="stock_valuation_layer_company_rule">
<field name="name">Stock Valuation Layer Multicompany</field>
<field name="model_id" search="[('model','=','stock.valuation.layer')]" model="ir.model"/>
@@ -26,7 +26,7 @@
<page string="Other Info" name="other_info">
<group>
<field name="description" />
<field name="account_move_id" attrs="{'invisible': [('account_move_id', '=', False)]}" />
<field name="account_move_id" groups="account.group_account_invoice" attrs="{'invisible': [('account_move_id', '=', False)]}" />
<field name="company_id" groups="base.group_multi_company" />
<field name="stock_valuation_layer_id" attrs="{'invisible': [('stock_valuation_layer_id', '=', False)]}" />
</group>

0 comments on commit 7b26611

Please sign in to comment.
You can’t perform that action at this time.