From 9978bcb366d0ea48ed25a7891e0c7653a2f96bfb Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Tue, 28 Jun 2022 09:47:14 +0000 Subject: [PATCH] [IMP] stock{_account}: inventory => locations report update Inventory report has been updated to have: - better applicability: report renamed to "Locations" and is only visible w/Locations, Consignment, or debug mode active - improved UX: list view rearranged, buttons added, grouping removed, sums added to bottom of list - improved quant "Value": instead of the accounting value, this is now the average unit cost (i.e. sum(valuation layer values)/sum(valuation layer quantities) per product x on hand qty (of quant). - single click load for products - search based on Warehouse option (including storing location.warehouse_id to avoid overly complex search function) - always show "Location" column in this view even if multi-locations is not active "inventory report" part of b2b task: 2882539 Upgrade PR: odoo/upgrade#3819 Part-of: odoo/odoo#97109 --- .../views/stock_quant_views.xml | 4 +- addons/stock/models/stock_location.py | 2 +- addons/stock/models/stock_quant.py | 11 +++- addons/stock/models/stock_warehouse.py | 4 ++ .../js/inventory_singleton_list_controller.js | 3 + addons/stock/views/stock_move_line_views.xml | 2 +- addons/stock/views/stock_orderpoint_views.xml | 2 +- addons/stock/views/stock_quant_views.xml | 62 ++++++++++--------- addons/stock_account/__manifest__.py | 2 +- addons/stock_account/models/stock_quant.py | 32 +++------- .../stock_account/views/stock_quant_views.xml | 3 +- 11 files changed, 67 insertions(+), 60 deletions(-) diff --git a/addons/product_expiry/views/stock_quant_views.xml b/addons/product_expiry/views/stock_quant_views.xml index 2fdb1a19f32..e16c047af1d 100644 --- a/addons/product_expiry/views/stock_quant_views.xml +++ b/addons/product_expiry/views/stock_quant_views.xml @@ -21,9 +21,9 @@ stock.quant - + - diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py index d34027d5217..6655f11dad1 100644 --- a/addons/stock/models/stock_location.py +++ b/addons/stock/models/stock_location.py @@ -90,7 +90,7 @@ class Location(models.Model): last_inventory_date = fields.Date("Last Effective Inventory", readonly=True, help="Date of the last inventory at this location.") next_inventory_date = fields.Date("Next Expected Inventory", compute="_compute_next_inventory_date", store=True, help="Date for next planned inventory based on cyclic schedule.") warehouse_view_ids = fields.One2many('stock.warehouse', 'view_location_id', readonly=True) - warehouse_id = fields.Many2one('stock.warehouse', compute='_compute_warehouse_id') + warehouse_id = fields.Many2one('stock.warehouse', compute='_compute_warehouse_id', store=True) storage_category_id = fields.Many2one('stock.storage.category', string='Storage Category', check_company=True) outgoing_move_line_ids = fields.One2many('stock.move.line', 'location_id') # used to compute weight incoming_move_line_ids = fields.One2many('stock.move.line', 'location_dest_id') # used to compute weight diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 8538a0320aa..4cce7c2cb88 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -3,6 +3,7 @@ import logging +from ast import literal_eval from psycopg2 import Error from odoo import _, api, fields, models @@ -67,6 +68,7 @@ class StockQuant(models.Model): 'stock.location', 'Location', domain=lambda self: self._domain_location_id(), auto_join=True, ondelete='restrict', required=True, index=True, check_company=True) + warehouse_id = fields.Many2one('stock.warehouse', related='location_id.warehouse_id') storage_category_id = fields.Many2one(related='location_id.storage_category_id', store=True) cyclic_inventory_frequency = fields.Integer(related='location_id.cyclic_inventory_frequency') lot_id = fields.Many2one( @@ -340,6 +342,11 @@ class StockQuant(models.Model): ] return action + def action_view_orderpoints(self): + action = self.env['product.product'].action_view_orderpoints() + action['domain'] = [('product_id', '=', self.product_id.id)] + return action + @api.model def action_view_quants(self): self = self.with_context(search_default_internal_loc=1) @@ -923,7 +930,7 @@ class StockQuant(models.Model): company_user = self.env.company warehouse = self.env['stock.warehouse'].search([('company_id', '=', company_user.id)], limit=1) if warehouse: - self = self.with_context(default_location_id=warehouse.lot_stock_id.id, hide_location=True) + self = self.with_context(default_location_id=warehouse.lot_stock_id.id, hide_location=not self.env.context.get('always_show_loc', False)) # If user have rights to write on quant, we set quants in inventory mode. if self.user_has_groups('stock.group_stock_user'): @@ -945,7 +952,7 @@ class StockQuant(models.Model): ctx['inventory_report_mode'] = True ctx.pop('group_by', None) action = { - 'name': _('Stock On Hand'), + 'name': _('Locations'), 'view_type': 'tree', 'view_mode': 'list,form', 'res_model': 'stock.quant', diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index cb56bf97842..0a34cbc6674 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -144,6 +144,10 @@ class Warehouse(models.Model): if vals.get('partner_id'): self._update_partner_data(vals['partner_id'], vals.get('company_id')) + # manually update locations' warehouse since it didn't exist at their creation time + view_location_id = self.env['stock.location'].browse(vals.get('view_location_id')) + (view_location_id | view_location_id.with_context(active_test=False).child_ids).write({'warehouse_id': warehouse.id}) + self._check_multiwarehouse_group() return warehouses diff --git a/addons/stock/static/src/js/inventory_singleton_list_controller.js b/addons/stock/static/src/js/inventory_singleton_list_controller.js index 07d28e3576a..c36ad06a04c 100644 --- a/addons/stock/static/src/js/inventory_singleton_list_controller.js +++ b/addons/stock/static/src/js/inventory_singleton_list_controller.js @@ -44,6 +44,9 @@ var SingletonListController = InventoryReportListController.extend({ */ renderButtons: function ($node) { this._super(...arguments); + if (this.context.inventory_report_mode) { + this.$buttons.find('button.o_button_apply_all').hide(); + } this.$buttons.on('click', '.o_button_apply_all', this._onApplyAll.bind(this)); }, diff --git a/addons/stock/views/stock_move_line_views.xml b/addons/stock/views/stock_move_line_views.xml index ccf127020e4..7094fc1c751 100644 --- a/addons/stock/views/stock_move_line_views.xml +++ b/addons/stock/views/stock_move_line_views.xml @@ -177,7 +177,7 @@ ir.actions.act_window tree,kanban,pivot,form - {'search_default_filter_last_12_months': 1, 'search_default_done': 1, 'search_default_groupby_product_id': 1, 'create': 0} + {'search_default_filter_last_12_months': 1, 'search_default_done': 1, 'create': 0}

There's no product move yet diff --git a/addons/stock/views/stock_orderpoint_views.xml b/addons/stock/views/stock_orderpoint_views.xml index dbd5eb76676..d3f74723404 100644 --- a/addons/stock/views/stock_orderpoint_views.xml +++ b/addons/stock/views/stock_orderpoint_views.xml @@ -51,7 +51,7 @@