From 806d0a52a150d04fbf7d2f46aa69977a36d4fe3d Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Sat, 11 May 2019 10:15:26 +0000 Subject: [PATCH] [REF] stock_account: stock inventory to is own file No changes on the code. task-1875873 --- addons/stock_account/models/__init__.py | 1 + addons/stock_account/models/stock.py | 39 ----------------- .../stock_account/models/stock_inventory.py | 43 +++++++++++++++++++ 3 files changed, 44 insertions(+), 39 deletions(-) create mode 100644 addons/stock_account/models/stock_inventory.py diff --git a/addons/stock_account/models/__init__.py b/addons/stock_account/models/__init__.py index a11616c850a..ee0668460d2 100644 --- a/addons/stock_account/models/__init__.py +++ b/addons/stock_account/models/__init__.py @@ -7,4 +7,5 @@ from . import account_move from . import account_reconciliation_widget from . import product from . import stock +from . import stock_inventory from . import res_config_settings diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py index 1deebbbb0db..c0ca61000fd 100644 --- a/addons/stock_account/models/stock.py +++ b/addons/stock_account/models/stock.py @@ -11,45 +11,6 @@ import logging _logger = logging.getLogger(__name__) -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_ref = self.env.ref('account.action_move_journal_line') - if not action_ref: - return False - action_data = action_ref.read()[0] - action_data['domain'] = [('stock_move_id.id', 'in', self.move_ids.ids)] - return action_data - - @api.multi - def post_inventory(self): - acc_inventories = self.filtered(lambda inventory: inventory.accounting_date) - for inventory in acc_inventories: - super(StockInventory, inventory.with_context(force_period_date=inventory.accounting_date)).post_inventory() - other_inventories = self - acc_inventories - if other_inventories: - super(StockInventory, other_inventories).post_inventory() - - class StockLocation(models.Model): _inherit = "stock.location" diff --git a/addons/stock_account/models/stock_inventory.py b/addons/stock_account/models/stock_inventory.py new file mode 100644 index 00000000000..a5ae3bfe0a2 --- /dev/null +++ b/addons/stock_account/models/stock_inventory.py @@ -0,0 +1,43 @@ +# -*- 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_ref = self.env.ref('account.action_move_journal_line') + if not action_ref: + return False + action_data = action_ref.read()[0] + action_data['domain'] = [('stock_move_id.id', 'in', self.move_ids.ids)] + return action_data + + def post_inventory(self): + acc_inventories = self.filtered(lambda inventory: inventory.accounting_date) + for inventory in acc_inventories: + super(StockInventory, inventory.with_context(force_period_date=inventory.accounting_date)).post_inventory() + other_inventories = self - acc_inventories + if other_inventories: + super(StockInventory, other_inventories).post_inventory() +