summaryrefslogtreecommitdiff
path: root/addons/stock_account/models/stock_inventory.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/stock_account/models/stock_inventory.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/stock_account/models/stock_inventory.py')
-rw-r--r--addons/stock_account/models/stock_inventory.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/addons/stock_account/models/stock_inventory.py b/addons/stock_account/models/stock_inventory.py
new file mode 100644
index 00000000..6dafe449
--- /dev/null
+++ b/addons/stock_account/models/stock_inventory.py
@@ -0,0 +1,42 @@
+# -*- 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