Make the computation of product domain inheritable
This commit is contained in:
@@ -29,7 +29,7 @@ import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PurchaseSuggestionGenerate(models.TransientModel):
|
||||
class PurchaseSuggestGenerate(models.TransientModel):
|
||||
_name = 'purchase.suggest.generate'
|
||||
_description = 'Start to generate the purchase suggestions'
|
||||
|
||||
@@ -68,6 +68,17 @@ class PurchaseSuggestionGenerate(models.TransientModel):
|
||||
}
|
||||
return sline
|
||||
|
||||
@api.model
|
||||
def _prepare_product_domain(self):
|
||||
product_domain = []
|
||||
if self.categ_ids:
|
||||
product_domain.append(
|
||||
('categ_id', 'child_of', self.categ_ids.ids))
|
||||
if self.seller_ids:
|
||||
product_domain.append(
|
||||
('seller_id', 'in', self.seller_ids.ids))
|
||||
return product_domain
|
||||
|
||||
@api.model
|
||||
def generate_products_dict(self):
|
||||
ppo = self.env['product.product']
|
||||
@@ -79,14 +90,8 @@ class PurchaseSuggestionGenerate(models.TransientModel):
|
||||
('location_id', 'child_of', self.location_id.id),
|
||||
]
|
||||
if self.categ_ids or self.seller_ids:
|
||||
product_domain = []
|
||||
if self.categ_ids:
|
||||
product_domain.append(
|
||||
('categ_id', 'child_of', self.categ_ids.ids))
|
||||
if self.seller_ids:
|
||||
product_domain.append(
|
||||
('seller_id', 'in', self.seller_ids.ids))
|
||||
products_subset = ppo.search(product_domain)
|
||||
|
||||
products_subset = ppo.search(self._prepare_product_domain())
|
||||
op_domain.append(('product_id', 'in', products_subset.ids))
|
||||
ops = swoo.search(op_domain)
|
||||
for op in ops:
|
||||
|
||||
@@ -46,17 +46,10 @@ class PurchaseSuggestionGenerate(models.TransientModel):
|
||||
def generate_products_dict(self):
|
||||
'''inherit the native method to use min_qty on product.product'''
|
||||
ppo = self.env['product.product']
|
||||
product_domain = []
|
||||
products = {}
|
||||
product_domain = self._prepare_product_domain()
|
||||
if self.product_type == 'product':
|
||||
product_domain.append(('type', '=', 'product'))
|
||||
if self.categ_ids or self.seller_ids:
|
||||
if self.categ_ids:
|
||||
product_domain.append(
|
||||
('categ_id', 'child_of', self.categ_ids.ids))
|
||||
if self.seller_ids:
|
||||
product_domain.append(
|
||||
('seller_id', 'in', self.seller_ids.ids))
|
||||
product_to_analyse = ppo.search(product_domain)
|
||||
for product in product_to_analyse:
|
||||
# We also want the missing product that have min_qty = 0
|
||||
|
||||
Reference in New Issue
Block a user