From f6d4dd8692f08be084297045c5058154c10e01b2 Mon Sep 17 00:00:00 2001 From: Jared Esparza Date: Wed, 19 Jan 2022 09:48:53 +0100 Subject: [PATCH] Add configuration.variant_deactivate_stock_zero check --- product.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/product.py b/product.py index 0d5dc15..fbcc140 100644 --- a/product.py +++ b/product.py @@ -128,16 +128,17 @@ class Product(WineMixin, metaclass=PoolMeta): locations = Location.search(['type', '=', 'warehouse']) locations = [location.id for location in locations] with Transaction().set_context(locations=locations, with_childs=True): - products = cls.search( - [ - ('quantity', '=', 0), - ('template.variant_deactivate_stock_zero', '=', True), - ('create_date', '<', - (datetime.now() - config.variant_deactivation_time)) - ]) - for product in products: - product.active = False - cls.save(products) + if config.variant_deactivation_time: + products = cls.search( + [ + ('quantity', '=', 0), + ('template.variant_deactivate_stock_zero', '=', True), + ('create_date', '<', + (datetime.now() - config.variant_deactivation_time)) + ]) + for product in products: + product.active = False + cls.save(products) @classmethod def validate(cls, products):