From cadbd840d999669515e2ed11cf54bed115cd2df1 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 12 Aug 2019 00:25:20 +0200 Subject: [PATCH] Add support for filter by location on inventory report and inventory valuation Refund option enabled by default on Return wizard --- sale_stock_usability/__init__.py | 1 - sale_stock_usability/wizard/__init__.py | 1 - .../wizard/stock_return_picking.py | 18 -------- stock_account_usability/__manifest__.py | 7 ++- ...y_valuation_by_location-stock_account.diff | 22 ++++++++++ stock_account_usability/wizard/__init__.py | 2 + .../wizard/stock_quantity_history.py | 35 +++++++++++++++ .../wizard/stock_quantity_history_view.xml | 23 ++++++++++ .../wizard/stock_return_picking.py | 17 +++++--- stock_usability/__init__.py | 1 + stock_usability/__manifest__.py | 1 + stock_usability/stock_view.xml | 43 ++++++++++++++++++- stock_usability/wizard/__init__.py | 3 ++ .../wizard/stock_quantity_history.py | 32 ++++++++++++++ .../wizard/stock_quantity_history_view.xml | 23 ++++++++++ 15 files changed, 201 insertions(+), 28 deletions(-) delete mode 100644 sale_stock_usability/wizard/__init__.py delete mode 100644 sale_stock_usability/wizard/stock_return_picking.py create mode 100644 stock_account_usability/inventory_valuation_by_location-stock_account.diff create mode 100644 stock_account_usability/wizard/__init__.py create mode 100644 stock_account_usability/wizard/stock_quantity_history.py create mode 100644 stock_account_usability/wizard/stock_quantity_history_view.xml create mode 100644 stock_usability/wizard/__init__.py create mode 100644 stock_usability/wizard/stock_quantity_history.py create mode 100644 stock_usability/wizard/stock_quantity_history_view.xml diff --git a/sale_stock_usability/__init__.py b/sale_stock_usability/__init__.py index ad8fbf5..d2b1458 100644 --- a/sale_stock_usability/__init__.py +++ b/sale_stock_usability/__init__.py @@ -1,2 +1 @@ from . import sale_stock -from . import wizard diff --git a/sale_stock_usability/wizard/__init__.py b/sale_stock_usability/wizard/__init__.py deleted file mode 100644 index 664e995..0000000 --- a/sale_stock_usability/wizard/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import stock_return_picking diff --git a/sale_stock_usability/wizard/stock_return_picking.py b/sale_stock_usability/wizard/stock_return_picking.py deleted file mode 100644 index c619804..0000000 --- a/sale_stock_usability/wizard/stock_return_picking.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2017-2019 Akretion France (https://akretion.com/) -# @author: Alexis de Lattre -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo import models, api - - -class StockReturnPicking(models.TransientModel): - _inherit = 'stock.return.picking' - - @api.model - def default_get(self, fields): - res = super(StockReturnPicking, self).default_get(fields) - if res.get('product_return_moves'): - for line in res['product_return_moves']: - if len(line) == 3: - line[2]['to_refund_so'] = True - return res diff --git a/stock_account_usability/__manifest__.py b/stock_account_usability/__manifest__.py index 8451dba..5ba8fda 100644 --- a/stock_account_usability/__manifest__.py +++ b/stock_account_usability/__manifest__.py @@ -16,13 +16,16 @@ Stock Account Usability The usability enhancements include: -* TODO update the list +* activate the refund option by default in return wizard on pickings + +* add ability to select a stock location on the inventory valuation report + This module has been written by Alexis de Lattre from Akretion . """, 'author': 'Akretion', 'website': 'http://www.akretion.com', 'depends': ['stock_account'], - 'data': [], + 'data': ['wizard/stock_quantity_history_view.xml'], 'installable': True, } diff --git a/stock_account_usability/inventory_valuation_by_location-stock_account.diff b/stock_account_usability/inventory_valuation_by_location-stock_account.diff new file mode 100644 index 0000000..a9f9eda --- /dev/null +++ b/stock_account_usability/inventory_valuation_by_location-stock_account.diff @@ -0,0 +1,22 @@ +diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py +index 0622c16d2b5..c078ac54324 100644 +--- a/addons/stock_account/models/product.py ++++ b/addons/stock_account/models/product.py +@@ -239,7 +239,7 @@ class ProductProduct(models.Model): + + for product in self: + if product.cost_method in ['standard', 'average']: +- qty_available = product.with_context(company_owned=True, owner_id=False).qty_available ++ qty_available = product.with_context(owner_id=False).qty_available + price_used = product.standard_price + if to_date: + price_used = product.get_history_price( +@@ -252,7 +252,7 @@ class ProductProduct(models.Model): + if to_date: + if product.product_tmpl_id.valuation == 'manual_periodic': + product.stock_value = product_values[product.id] +- product.qty_at_date = product.with_context(company_owned=True, owner_id=False).qty_available ++ product.qty_at_date = product.with_context(owner_id=False).qty_available + product.stock_fifo_manual_move_ids = StockMove.browse(product_move_ids[product.id]) + elif product.product_tmpl_id.valuation == 'real_time': + valuation_account_id = product.categ_id.property_stock_valuation_account_id.id diff --git a/stock_account_usability/wizard/__init__.py b/stock_account_usability/wizard/__init__.py new file mode 100644 index 0000000..414f00a --- /dev/null +++ b/stock_account_usability/wizard/__init__.py @@ -0,0 +1,2 @@ +from . import stock_return_picking +from . import stock_quantity_history diff --git a/stock_account_usability/wizard/stock_quantity_history.py b/stock_account_usability/wizard/stock_quantity_history.py new file mode 100644 index 0000000..0eab5b2 --- /dev/null +++ b/stock_account_usability/wizard/stock_quantity_history.py @@ -0,0 +1,35 @@ +# Copyright 2019 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockQuantityHistory(models.TransientModel): + _inherit = 'stock.quantity.history' + + def open_table(self): + action = super(StockQuantityHistory, self).open_table() + if self.location_id and self.env.context.get('valuation'): + # When we have 'valuation' in context + # in both cases ('current inventory' and 'at specific date') + # it returns an action on product.product, + # the only difference is the context. + # We have to make the same modifications, but + # when self.compute_at_date, action['context'] is a dict + # otherwize, action['context'] is a string + if self.compute_at_date: + # insert "location" in context for qty computation + action['context']['location'] = self.location_id.id + # When company_owned=True, the 'location' given in the + # context is not taken into account + # IMPORTANT: also requires a patch on the stock_account + # module. Patch provided in this module. + action['context']['company_owned'] = False + else: + action['context'] = { + 'location': self.location_id.id, + 'create': False, + 'edit': False, + } + return action diff --git a/stock_account_usability/wizard/stock_quantity_history_view.xml b/stock_account_usability/wizard/stock_quantity_history_view.xml new file mode 100644 index 0000000..514e6bb --- /dev/null +++ b/stock_account_usability/wizard/stock_quantity_history_view.xml @@ -0,0 +1,23 @@ + + + + + + + + stock_account_usability.stock.quantity.history.form + stock.quantity.history + + + + + + + + + + diff --git a/stock_account_usability/wizard/stock_return_picking.py b/stock_account_usability/wizard/stock_return_picking.py index f04db55..12221c6 100644 --- a/stock_account_usability/wizard/stock_return_picking.py +++ b/stock_account_usability/wizard/stock_return_picking.py @@ -1,12 +1,19 @@ -# -*- coding: utf-8 -*- # Copyright 2019 Akretion France (https://akretion.com/) # @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields +from odoo import api, models -class StockReturnPickingLine(models.TransientModel): - _inherit = 'stock.return.picking.line' +class StockReturnPicking(models.TransientModel): + _inherit = 'stock.return.picking' - to_refund = fields.Boolean(default=True) + # Set to_refund to True by default + @api.model + def default_get(self, fields_list): + res = super(StockReturnPicking, self).default_get(fields_list) + if isinstance(res.get('product_return_moves'), list): + for l in res['product_return_moves']: + if len(l) == 3 and isinstance(l[2], dict): + l[2]['to_refund'] = True + return res diff --git a/stock_usability/__init__.py b/stock_usability/__init__.py index 9781d47..444b4bf 100644 --- a/stock_usability/__init__.py +++ b/stock_usability/__init__.py @@ -4,3 +4,4 @@ from . import stock from . import procurement from . import product from . import partner +from . import wizard diff --git a/stock_usability/__manifest__.py b/stock_usability/__manifest__.py index d615109..3476748 100644 --- a/stock_usability/__manifest__.py +++ b/stock_usability/__manifest__.py @@ -28,6 +28,7 @@ This module has been written by Alexis de Lattre from Akretion + + + + stock.quant.search with child_of for locations + stock.quant + + + + + + + + + + + + + + + + + + + + + + + + + + + but it forces a group by on products that you can't remove So I create another "regular" Quants" menu entry --> - Quants List + Quants stock.quant tree,form,pivot {'search_default_internal_loc': 1} + + + Quants + stock.quant + tree,form,pivot + + + + diff --git a/stock_usability/wizard/__init__.py b/stock_usability/wizard/__init__.py new file mode 100644 index 0000000..bf9d6de --- /dev/null +++ b/stock_usability/wizard/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import stock_quantity_history diff --git a/stock_usability/wizard/stock_quantity_history.py b/stock_usability/wizard/stock_quantity_history.py new file mode 100644 index 0000000..9626c40 --- /dev/null +++ b/stock_usability/wizard/stock_quantity_history.py @@ -0,0 +1,32 @@ +# Copyright 2019 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class StockQuantityHistory(models.TransientModel): + _inherit = 'stock.quantity.history' + + location_id = fields.Many2one( + 'stock.location', string='Stock Location', + domain=[('usage', '=', 'internal')], + help="If you select a stock location, the inventory report will be " + "for this stock location and its children locations. If you leave " + "this field empty, the inventory report will be for all the internal " + "stock locations.") + + def open_table(self): + action = super(StockQuantityHistory, self).open_table() + if self.compute_at_date: + action['domain'] = "[('type', '=', 'product'), ('qty_available', '!=', 0)]" + if self.location_id: + if self.compute_at_date: + # insert "location" in context for qty computation + action['context']['location'] = self.location_id.id + else: + # force search view with child_of for location_id + action = self.env.ref( + 'stock_usability.stock_quantity_history_quant_action').read()[0] + action['context'] = {'search_default_location_id': self.location_id.id} + return action diff --git a/stock_usability/wizard/stock_quantity_history_view.xml b/stock_usability/wizard/stock_quantity_history_view.xml new file mode 100644 index 0000000..93fa96e --- /dev/null +++ b/stock_usability/wizard/stock_quantity_history_view.xml @@ -0,0 +1,23 @@ + + + + + + + + stock_usability.stock.quantity.history.form + stock.quantity.history + + + + + + + + + +