From 252fb209734ce82cac33a061f1c22cee230f2d9c Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 25 Aug 2021 15:24:35 +0200 Subject: [PATCH] [ADD] stock_inventory_preparation_filter_pos: filter inventory on POS categs This module replaces the module stock_inventory_pos_category proposed in this PR for odoo v10: https://github.com/OCA/stock-logistics-warehouse/pull/393 Adapt stock_inventory_preparation_filter to allow inheritance by adding a prepare method --- .../models/stock_inventory.py | 30 ++++++++++++------- .../views/stock_inventory_view.xml | 4 +-- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/stock_inventory_preparation_filter/models/stock_inventory.py b/stock_inventory_preparation_filter/models/stock_inventory.py index 9197f5796992..2c67721ab283 100644 --- a/stock_inventory_preparation_filter/models/stock_inventory.py +++ b/stock_inventory_preparation_filter/models/stock_inventory.py @@ -52,18 +52,26 @@ def _selection_filter(self): product_domain = fields.Char("Domain", default=[("name", "ilike", "")]) def _action_start(self): - Product = self.env["product.product"] for inventory in self: - products = Product.browse() if inventory.state != "draft": continue - if inventory.filter == "categories": - products = Product.search([("categ_id", "in", inventory.categ_ids.ids)]) - if inventory.filter == "lots": - products = inventory.lot_ids.mapped("product_id") - if inventory.filter == "domain": - domain = safe_eval(inventory.product_domain) - products = Product.search(domain) - if products: - inventory.product_ids = [(6, 0, products.ids)] + if inventory.filter: + products = inventory._prepare_inventory_filter() + if products: + inventory.product_ids = [(6, 0, products.ids)] return super()._action_start() + + def _prepare_inventory_filter(self): + # This method is designed to be inherited by other modules + # such as the OCA module stock_inventory_preparation_filter_pos + self.ensure_one() + Product = self.env["product.product"] + products = Product + if self.filter == "categories": + products = Product.search([("categ_id", "in", self.categ_ids.ids)]) + elif self.filter == "lots": + products = self.lot_ids.product_id + elif self.filter == "domain": + domain = safe_eval(self.product_domain) + products = Product.search(domain) + return products diff --git a/stock_inventory_preparation_filter/views/stock_inventory_view.xml b/stock_inventory_preparation_filter/views/stock_inventory_view.xml index e71cd0168611..a6ada2253fb5 100644 --- a/stock_inventory_preparation_filter/views/stock_inventory_view.xml +++ b/stock_inventory_preparation_filter/views/stock_inventory_view.xml @@ -34,12 +34,12 @@