From 50f77ba091189bd785d459c042a6cec04a125fdb Mon Sep 17 00:00:00 2001 From: len-odoo Date: Tue, 24 Apr 2018 11:08:56 +0200 Subject: [PATCH] [FIX] stock: allow inventory user to validate delivery orders when accouting entries have to be created When validating a delivery order with automated inventory, some accounting moves are created. Since an inventory user might not have accounting rights, the validation of delivery orders might fail. We simply had a sudo when in the internal method creating the move. Moreover if the inventory valuation is set in FIFO, the product price might be updated. It might fail for lack of additional rights. We add a sudo for this price update. opw 1836761 --- addons/account/models/account_move.py | 3 +-- addons/stock_account/models/stock.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index f5b5835e6ef..b2daa735434 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -102,8 +102,7 @@ class AccountMove(models.Model): partner_id = fields.Many2one('res.partner', compute='_compute_partner_id', string="Partner", store=True, readonly=True) amount = fields.Monetary(compute='_amount_compute', store=True) narration = fields.Text(string='Internal Note') - company_id = fields.Many2one('res.company', related='journal_id.company_id', string='Company', store=True, readonly=True, - default=lambda self: self.env.user.company_id) + company_id = fields.Many2one('res.company', related='journal_id.company_id', string='Company', store=True, readonly=True) matched_percentage = fields.Float('Percentage Matched', compute='_compute_matched_percentage', digits=0, store=True, readonly=True, help="Technical field used in cash basis method") # Dummy Account field to search on account.move by account_id dummy_account_id = fields.Many2one('account.account', related='line_ids.account_id', string='Account', store=False, readonly=True) diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py index d6800a1b7c7..3d73e4d100e 100644 --- a/addons/stock_account/models/stock.py +++ b/addons/stock_account/models/stock.py @@ -260,7 +260,7 @@ class StockMove(models.Model): # Update the standard price with the price of the last used candidate, if any. if new_standard_price and move.product_id.cost_method == 'fifo': - move.product_id.standard_price = new_standard_price + move.product_id.sudo().standard_price = new_standard_price # If there's still quantity to value but we're out of candidates, we fall in the # negative stock use case. We chose to value the out move at the price of the @@ -591,7 +591,7 @@ class StockMove(models.Model): move_lines = self.with_context(forced_ref=ref)._prepare_account_move_line(quantity, abs(self.value), credit_account_id, debit_account_id) if move_lines: date = self._context.get('force_period_date', fields.Date.context_today(self)) - new_account_move = AccountMove.create({ + new_account_move = AccountMove.sudo().create({ 'journal_id': journal_id, 'line_ids': move_lines, 'date': date,