Files
odoo_source/addons/stock_account/models/stock_inventory.py
T
Martin TrigauxandXavier Morel 49838338e0 [FIX] *: sanitize action content reading
The open_action_with_context was not using _for_xml_id, producing an
error when reading the action content.

In open_action, the action_name was taken from the context and needs
sanity checks. Ensure only actions from the account module can be
read and only if the user has access to the target model.
This is a limitation of the previous behaviour but, at the moment, all
known calls are made refering to an action from the account module.
Limit the scope of this method while the 14.0 is still early to avoid
having a door open to ready any action, and difficult to close later.

Remove old action fetching from the context in create_move that is no
longer used.

closes odoo/odoo#61602

X-original-commit: a39e94f7e4dc74e850650ac90bbc5f85af130bc8
Related: odoo/enterprise#14695
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
Co-authored-by: Xavier Morel <xmo@odoo.com>
2020-11-10 16:04:29 +00:00

43 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class StockInventory(models.Model):
_inherit = "stock.inventory"
accounting_date = fields.Date(
'Accounting Date',
help="Date at which the accounting entries will be created"
" in case of automated inventory valuation."
" If empty, the inventory date will be used.")
has_account_moves = fields.Boolean(compute='_compute_has_account_moves')
def _compute_has_account_moves(self):
for inventory in self:
if inventory.state == 'done' and inventory.move_ids:
account_move = self.env['account.move'].search_count([
('stock_move_id.id', 'in', inventory.move_ids.ids)
])
inventory.has_account_moves = account_move > 0
else:
inventory.has_account_moves = False
def action_get_account_moves(self):
self.ensure_one()
action_data = self.env['ir.actions.act_window']._for_xml_id('account.action_move_journal_line')
action_data['domain'] = [('stock_move_id.id', 'in', self.move_ids.ids)]
action_data['context'] = dict(self._context, create=False)
return action_data
def post_inventory(self):
res = True
acc_inventories = self.filtered(lambda inventory: inventory.accounting_date)
for inventory in acc_inventories:
res = super(StockInventory, inventory.with_context(force_period_date=inventory.accounting_date)).post_inventory()
other_inventories = self - acc_inventories
if other_inventories:
res = super(StockInventory, other_inventories).post_inventory()
return res