From ce4da0531dc18d68f0943e46a1ebe779761f8013 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Mon, 18 Sep 2017 17:34:28 +0200 Subject: [PATCH] [REF] stock, stock_account: inventory and valuation report Kind of switches the behavior for inventory and valuation report, meaning allows the user to see the quantity at date and disallow him to see the valuation at date. --- addons/stock/__manifest__.py | 1 + addons/stock/views/stock_quant_views.xml | 12 ----- addons/stock/wizard/__init__.py | 1 + addons/stock/wizard/stock_quantity_history.py | 36 ++++++++++++++ .../wizard/stock_quantity_history.xml} | 19 ++++---- addons/stock_account/__manifest__.py | 5 +- .../stock_account/data/stock_account_data.xml | 23 ++++++++- addons/stock_account/models/product.py | 8 ++-- addons/stock_account/views/product_views.xml | 2 +- .../views/stock_account_views.xml | 40 +--------------- addons/stock_account/wizard/__init__.py | 2 +- .../wizard/wizard_valuation_history.py | 48 ------------------- 12 files changed, 79 insertions(+), 118 deletions(-) create mode 100644 addons/stock/wizard/stock_quantity_history.py rename addons/{stock_account/wizard/wizard_valuation_history_views.xml => stock/wizard/stock_quantity_history.xml} (56%) delete mode 100644 addons/stock_account/wizard/wizard_valuation_history.py diff --git a/addons/stock/__manifest__.py b/addons/stock/__manifest__.py index ad51ea5df42..1e0b96a8ecc 100644 --- a/addons/stock/__manifest__.py +++ b/addons/stock/__manifest__.py @@ -43,6 +43,7 @@ 'wizard/stock_immediate_transfer_views.xml', 'wizard/stock_backorder_confirmation_views.xml', 'wizard/stock_overprocessed_transfer_views.xml', + 'wizard/stock_quantity_history.xml', 'views/res_partner_views.xml', 'views/product_strategy_views.xml', diff --git a/addons/stock/views/stock_quant_views.xml b/addons/stock/views/stock_quant_views.xml index 600793b5354..b521327ee90 100644 --- a/addons/stock/views/stock_quant_views.xml +++ b/addons/stock/views/stock_quant_views.xml @@ -139,18 +139,6 @@ stock.quant - - Merge duplicate quants - - code - -env['stock.quant']._merge_quants() -action = env.ref('stock.quantsact').read()[0] - - - - - stock.quant.package.search stock.quant.package diff --git a/addons/stock/wizard/__init__.py b/addons/stock/wizard/__init__.py index b07f880122e..f9b6c34bcec 100644 --- a/addons/stock/wizard/__init__.py +++ b/addons/stock/wizard/__init__.py @@ -7,3 +7,4 @@ from . import stock_scheduler_compute from . import stock_immediate_transfer from . import stock_backorder_confirmation from . import stock_overprocessed_transfer +from . import stock_quantity_history diff --git a/addons/stock/wizard/stock_quantity_history.py b/addons/stock/wizard/stock_quantity_history.py new file mode 100644 index 00000000000..16dee8b4de1 --- /dev/null +++ b/addons/stock/wizard/stock_quantity_history.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, _ + + +class StockQuantityHistory(models.TransientModel): + _name = 'stock.quantity.history' + _description = 'Stock Quantity History' + + compute_at_date = fields.Selection([ + (0, 'Current Inventory'), + (1, 'At a Specific Date') + ], string="Compute", help="Choose to analyze the current inventory or from a specific date in the past.") + date = fields.Datetime('Inventory at Date', help="Choose a date to get the inventory at that date", default=fields.Datetime.now()) + + def open_table(self): + self.ensure_one() + + if self.compute_at_date: + tree_view_id = self.env.ref('stock.view_stock_product_tree').id + form_view_id = self.env.ref('stock.product_form_view_procurement_button').id + # We pass `to_date` in the context so that `qty_available` will be computed across + # moves until date. + action = { + 'type': 'ir.actions.act_window', + 'views': [(tree_view_id, 'tree'), (form_view_id, 'form')], + 'view_mode': 'tree,form', + 'name': _('Products'), + 'res_model': 'product.product', + 'context': dict(self.env.context, to_date=self.date), + } + return action + else: + self.env['stock.quant']._merge_quants() + return self.env.ref('stock.quantsact').read()[0] diff --git a/addons/stock_account/wizard/wizard_valuation_history_views.xml b/addons/stock/wizard/stock_quantity_history.xml similarity index 56% rename from addons/stock_account/wizard/wizard_valuation_history_views.xml rename to addons/stock/wizard/stock_quantity_history.xml index 2413dc88537..d4d2c4aa494 100644 --- a/addons/stock_account/wizard/wizard_valuation_history_views.xml +++ b/addons/stock/wizard/stock_quantity_history.xml @@ -1,8 +1,8 @@ - - Inventory Valuation Report - wizard.valuation.history + + Inventory Report + stock.quantity.history
@@ -12,20 +12,21 @@
-
- - Inventory Valuation Report - wizard.valuation.history + + Inventory Report + stock.quantity.history form form - + new {'default_compute_at_date': 0} - +
+ diff --git a/addons/stock_account/__manifest__.py b/addons/stock_account/__manifest__.py index 4ee5c1b8468..d3b7ebdf773 100644 --- a/addons/stock_account/__manifest__.py +++ b/addons/stock_account/__manifest__.py @@ -30,12 +30,11 @@ Dashboard / Reports for Warehouse Management includes: 'security/stock_account_security.xml', 'security/ir.model.access.csv', 'wizard/stock_change_standard_price_views.xml', - 'wizard/wizard_valuation_history_views.xml', - 'views/product_views.xml', + 'data/stock_account_data.xml', 'views/stock_account_views.xml', 'views/res_config_settings_views.xml', 'data/product_data.xml', - 'data/stock_account_data.xml', + 'views/product_views.xml', 'data/stock_account_data_post_install.yml', ], 'test': [ diff --git a/addons/stock_account/data/stock_account_data.xml b/addons/stock_account/data/stock_account_data.xml index f3bffa3a6d3..f8957f2cd95 100644 --- a/addons/stock_account/data/stock_account_data.xml +++ b/addons/stock_account/data/stock_account_data.xml @@ -26,5 +26,26 @@ manual_periodic selection
+ + Stock Valuation Report + ir.actions.server + code + + + +# Call `_fifo_vacuum` on concerned moves +fifo_valued_products = env['product.product'] +fifo_valued_products |= env['product.template'].search([('property_cost_method', '=', 'fifo')]).mapped('product_variant_ids') +fifo_valued_categories = env['product.category'].search([('property_cost_method', '=', 'fifo')]) +fifo_valued_products |= env['product.product'].search([('categ_id', 'child_of', fifo_valued_categories.ids)]) +moves_to_vacuum = env['stock.move'] +Move = env['stock.move'] +for product in fifo_valued_products: + moves_to_vacuum |= Move.search([('product_id', '=', product.id), ('remaining_qty', '<', 0)] + Move._get_all_base_domain()) +moves_to_vacuum._fifo_vacuum() +action = env.ref('stock_account.product_valuation_action').read()[0] + + - \ No newline at end of file + + diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index 897bfb34dba..3ffa85aff07 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -77,8 +77,8 @@ class ProductTemplate(models.Model): @api.multi def action_open_product_moves(self): self.ensure_one() - action = self.env.ref('stock_account.stock_move_valuation_action').read()[0] - action['domain'] = [('product_id.product_tmpl_id', '=', self.id)] + action = self.env.ref('stock_account.product_valuation_action').read()[0] + action['domain'] = [('product_tmpl_id', '=', self.id)] action['context'] = { 'search_default_outgoing': True, 'search_default_incoming': True, @@ -172,8 +172,8 @@ class ProductProduct(models.Model): @api.multi def action_open_product_moves(self): self.ensure_one() - action = self.env.ref('stock_account.stock_move_valuation_action').read()[0] - action['domain'] = [('product_id', '=', self.id)] + action = self.env.ref('stock_account.product_valuation_action').read()[0] + action['domain'] = [('id', '=', self.id)] action['context'] = { 'search_default_outgoing': True, 'search_default_incoming': True, diff --git a/addons/stock_account/views/product_views.xml b/addons/stock_account/views/product_views.xml index ccffae3bfc5..741dd98230b 100644 --- a/addons/stock_account/views/product_views.xml +++ b/addons/stock_account/views/product_views.xml @@ -107,7 +107,7 @@ tree,form form - [('type', '=', 'product')] + [('type', '=', 'product'), ('qty_available', '!=', 0)] {}

diff --git a/addons/stock_account/views/stock_account_views.xml b/addons/stock_account/views/stock_account_views.xml index 4c236103ae2..20c8f9fcd3b 100644 --- a/addons/stock_account/views/stock_account_views.xml +++ b/addons/stock_account/views/stock_account_views.xml @@ -49,44 +49,6 @@ - - stock.move.tree.valuation - stock.move - - - - - - - - - - - - - - - - - - - - - - - - Stock Moves - stock.move - ir.actions.act_window - form - - - {'search_default_outgoing': 1, 'search_default_incoming': 1, 'search_default_done': 1, 'search_default_group_by_product': 1} - -

- Click to create a stock movement. -

-
- + diff --git a/addons/stock_account/wizard/__init__.py b/addons/stock_account/wizard/__init__.py index bef8d18b84e..3fbd834da9f 100644 --- a/addons/stock_account/wizard/__init__.py +++ b/addons/stock_account/wizard/__init__.py @@ -2,4 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import stock_change_standard_price -from . import wizard_valuation_history + diff --git a/addons/stock_account/wizard/wizard_valuation_history.py b/addons/stock_account/wizard/wizard_valuation_history.py deleted file mode 100644 index 0836b516fff..00000000000 --- a/addons/stock_account/wizard/wizard_valuation_history.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import api, models, fields, _ - - -class WizardValuationHistory(models.TransientModel): - _name = 'wizard.valuation.history' - _description = 'Wizard that opens the stock valuation history table' - - compute_at_date = fields.Selection([ - (0, 'Current Inventory'), - (1, 'At a Specific Date') - ], string="Compute", help="Choose to analyze the current inventory or from a specific date in the past.") - date = fields.Datetime('Inventory at Date', help="Choose a date to get the inventory at that date", default=fields.Datetime.now()) - - @api.multi - def open_table(self): - self.ensure_one() - - # Call `_fifo_vacuum` on concerned moves - fifo_valued_products = self.env['product.product'] - fifo_valued_products |= self.env['product.template'].search([('property_cost_method', '=', 'fifo')]).mapped('product_variant_ids') - fifo_valued_categories = self.env['product.category'].search([('property_cost_method', '=', 'fifo')]) - fifo_valued_products |= self.env['product.product'].search([('categ_id', 'child_of', fifo_valued_categories.ids)]) - moves_to_vacuum = self.env['stock.move'] - Move = self.env['stock.move'] - for product in fifo_valued_products: - moves_to_vacuum |= Move.search([('product_id', '=', product.id), ('remaining_qty', '<', 0)] + Move._get_all_base_domain()) - moves_to_vacuum._fifo_vacuum() - - if self.compute_at_date and self.date: - action = self.env['ir.model.data'].xmlid_to_object('stock_account.stock_move_valuation_action') - if not action: - action = { - 'view_type': 'form', - 'view_mode': 'tree', - 'res_model': 'stock.move', - 'type': 'ir.actions.act_window', - } - else: - action = action[0].read()[0] - - action['domain'] = "[('date', '<=', '" + self.date + "')]" - action['name'] = _('Stock Value At Date') - else: - action = self.env.ref('stock_account.product_valuation_action').read()[0] - return action