From 51fb6f0c06141038625dce74a9c1bd98c5d7c606 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Thu, 31 Jan 2019 17:25:37 +0100 Subject: [PATCH] [FIX+IMP] stock_inventory_exclude_sublocation: Don't mess inheritance It also includes the removal of an unneeded dependency + better position of the field in view --- .../README.rst | 1 + .../__manifest__.py | 8 +- .../models/stock_inventory.py | 86 +++---------------- .../static/description/index.html | 1 + .../views/stock_inventory_view.xml | 7 +- 5 files changed, 26 insertions(+), 77 deletions(-) diff --git a/stock_inventory_exclude_sublocation/README.rst b/stock_inventory_exclude_sublocation/README.rst index 0ef81649a..459f9ae46 100644 --- a/stock_inventory_exclude_sublocation/README.rst +++ b/stock_inventory_exclude_sublocation/README.rst @@ -66,6 +66,7 @@ Authors ~~~~~~~ * Eficent +* Tecnativa Contributors ~~~~~~~~~~~~ diff --git a/stock_inventory_exclude_sublocation/__manifest__.py b/stock_inventory_exclude_sublocation/__manifest__.py index 8fbb5a94c..133d69b48 100644 --- a/stock_inventory_exclude_sublocation/__manifest__.py +++ b/stock_inventory_exclude_sublocation/__manifest__.py @@ -1,17 +1,21 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. # (http://www.eficent.com) +# Copyright 2019 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Stock Inventory Exclude Sublocation", "summary": "Allow to perform inventories of a location without including " "its child locations.", - "version": "11.0.1.0.0", + "version": "11.0.2.0.0", "development_status": "Mature", "author": "Eficent, " + "Tecnativa, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", "category": "Warehouse Management", - "depends": ["stock", "stock_inventory_chatter"], + "depends": [ + "stock", + ], "data": [ 'views/stock_inventory_view.xml', ], diff --git a/stock_inventory_exclude_sublocation/models/stock_inventory.py b/stock_inventory_exclude_sublocation/models/stock_inventory.py index 918addddb..c242123d3 100644 --- a/stock_inventory_exclude_sublocation/models/stock_inventory.py +++ b/stock_inventory_exclude_sublocation/models/stock_inventory.py @@ -1,5 +1,6 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. # (http://www.eficent.com) +# Copyright 2019 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import fields, models @@ -14,77 +15,16 @@ class Inventory(models.Model): states={'draft': [('readonly', False)]}) def _get_inventory_lines_values(self): - """This method is a copy of standard one but considering only the - current location. - WARNING: In case of excluding sublocations standard method - is overridden by this one.""" + """Discard inventory lines that are from sublocations if option + is enabled. + + Done this way for maximizing inheritance compatibility. + """ + vals = super()._get_inventory_lines_values() if not self.exclude_sublocation: - # Early return if exclude_sublocation is not set - return super()._get_inventory_lines_values() - - # STAR OF MODIFIED CODE: - domain = ' location_id in %s' - args = (tuple(self.location_id.ids),) - # END OF MODIFIED CODE. - - vals = [] - Product = self.env['product.product'] - # Empty recordset of products available in stock_quants - quant_products = self.env['product.product'] - # Empty recordset of products to filter - products_to_filter = self.env['product.product'] - - # case 0: Filter on company - if self.company_id: - domain += ' AND company_id = %s' - args += (self.company_id.id,) - - # case 1: Filter on One owner only or One product for a specific owner - if self.partner_id: - domain += ' AND owner_id = %s' - args += (self.partner_id.id,) - # case 2: Filter on One Lot/Serial Number - if self.lot_id: - domain += ' AND lot_id = %s' - args += (self.lot_id.id,) - # case 3: Filter on One product - if self.product_id: - domain += ' AND product_id = %s' - args += (self.product_id.id,) - products_to_filter |= self.product_id - # case 4: Filter on A Pack - if self.package_id: - domain += ' AND package_id = %s' - args += (self.package_id.id,) - # case 5: Filter on One product category + Exahausted Products - if self.category_id: - categ_products = Product.search( - [('categ_id', '=', self.category_id.id)]) - domain += ' AND product_id = ANY (%s)' - args += (categ_products.ids,) - products_to_filter |= categ_products - - self.env.cr.execute(""" - SELECT product_id, sum(quantity) as product_qty, - location_id, lot_id as prod_lot_id, package_id, - owner_id as partner_id - FROM stock_quant - WHERE %s - GROUP BY product_id, location_id, lot_id, - package_id, partner_id """ % domain, args) - - for product_data in self.env.cr.dictfetchall(): - for void_field in [item[0] for item in product_data.items() if - item[1] is None]: - product_data[void_field] = False - product_data['theoretical_qty'] = product_data['product_qty'] - if product_data['product_id']: - product_data['product_uom_id'] = Product.browse( - product_data['product_id']).uom_id.id - quant_products |= Product.browse(product_data['product_id']) - vals.append(product_data) - if self.exhausted: - exhausted_vals = self._get_exhausted_inventory_line( - products_to_filter, quant_products) - vals.extend(exhausted_vals) - return vals + return vals + new_vals = [] + for val in vals: + if val['location_id'] == self.location_id.id: + new_vals.append(val) + return new_vals diff --git a/stock_inventory_exclude_sublocation/static/description/index.html b/stock_inventory_exclude_sublocation/static/description/index.html index ba36f547d..d92e92108 100644 --- a/stock_inventory_exclude_sublocation/static/description/index.html +++ b/stock_inventory_exclude_sublocation/static/description/index.html @@ -412,6 +412,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

Authors

diff --git a/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml b/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml index a0fb1b83e..0a6d46d43 100644 --- a/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml +++ b/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml @@ -1,5 +1,6 @@ @@ -9,8 +10,10 @@ stock.inventory - - + +