Skip to content

Commit

Permalink
[ADD] stock_inventory_preparation_filter_pos: filter inventory on POS…
Browse files Browse the repository at this point in the history
… categs

This module replaces the module stock_inventory_pos_category proposed in
this PR for odoo v10: OCA#393

Adapt stock_inventory_preparation_filter to allow inheritance by adding
a prepare method
  • Loading branch information
alexis-via authored and AlexPForgeFlow committed Nov 27, 2023
1 parent 9721cfa commit 59244da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
30 changes: 19 additions & 11 deletions stock_inventory_preparation_filter/models/stock_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
<field
name="categ_ids"
widget="many2many_tags"
attrs="{'invisible':[('filter','!=','categories')]}"
attrs="{'invisible':[('filter','!=','categories')], 'required': [('filter','=','categories')]}"
/>
<field
name="lot_ids"
widget="many2many_tags"
attrs="{'invisible':[('filter','!=','lots')]}"
attrs="{'invisible':[('filter','!=','lots')], 'required': [('filter','=','lots')]}"
/>
</field>
</field>
Expand Down

0 comments on commit 59244da

Please sign in to comment.