def mutate(self, info, **kwargs): promotion_id = kwargs.get('promotion_id') user = info.context.user promotion = get_model_object(Promotion, 'id', promotion_id) check_user_is_active_in_outlet(user, outlet=promotion.outlet) promotion.delete(user) return DeletePromotion( success=SUCCESS_RESPONSES["deletion_success"].format("Promotion"))
def mutate(self, info, **kwargs): promotion_id = kwargs.get('promotion_id') user = info.context.user promotion = get_model_object(Promotion, 'id', promotion_id) check_user_is_active_in_outlet(user, outlet=promotion.outlet) promotion.is_approved = True promotion.save() return ApprovePromotion( success=SALES_SUCCESS_RESPONSES["promotion_approval_success"], promotion=promotion)
def mutate(self, info, **kwargs): promotion = validate_fields(Promotion(), **kwargs) outlet_id = kwargs.get('outlet_id') user = info.context.user check_user_is_active_in_outlet(user, outlet_id=outlet_id) with SaveContextManager(promotion, model=Promotion) as promotion: product_ids = kwargs.get('product_ids', []) promotion = add_products_to_promotion(promotion, product_ids) return CreatePromotion( success=SUCCESS_RESPONSES["creation_success"].format( "Promotion"), promotion=promotion)
def mutate(self, info, **kwargs): outlet_id = kwargs.get('outlet_id') user = info.context.user check_user_is_active_in_outlet(user, outlet_id=outlet_id) today_date = datetime.now() twelve_month = today_date + relativedelta(months=+12) outlet = get_model_object(Outlet, 'id', outlet_id) near_expired_products = Product.objects \ .for_business(outlet.business.id) \ .filter(nearest_expiry_date__range=(today_date, twelve_month)) promotion_set = set_recommended_promotion(Promotion, near_expired_products) return CreateRecommendedPromotion( success='Promotion set on {} product(s)'.format(promotion_set))
def mutate(self, info, **kwargs): promotion_id = kwargs.pop('promotion_id') user = info.context.user promotion = get_model_object(Promotion, 'id', promotion_id) check_user_is_active_in_outlet(user, outlet=promotion.outlet) product_ids = \ kwargs.pop('product_ids') if kwargs.get('product_ids') else [] validate_fields(Promotion(), **kwargs) for (key, value) in kwargs.items(): setattr(promotion, key, value) with SaveContextManager(promotion, model=Promotion) as promotion: promotion = add_products_to_promotion(promotion, product_ids) return UpdatePromotion( success=SUCCESS_RESPONSES["update_success"].format( "Promotion"), promotion=promotion)
def mutate(self, info, **kwargs): promotion_id = kwargs.get('promotion_id') product_id = kwargs.get('product_id') apply_months = kwargs.get('apply_months') if apply_months < 1 or apply_months > 12: raise GraphQLError('Months must be between 1 and 12') user = info.context.user promotion = get_model_object(Promotion, 'id', promotion_id) product = get_model_object(Product, 'id', product_id) applied_date = product.nearest_expiry_date - relativedelta( months=+apply_months) promotion_product = promotion.products.filter(id=product_id) check_user_is_active_in_outlet(user, outlet=promotion.outlet) if not promotion_product: promotion.products.add(product) promotion.applied_date = applied_date promotion.save() return CreateCustomNearExpirePromotion( success='Promotion was generated successfully', product=product)
def resolve_promotions_pending_approval(self, info, **kwargs): user = info.context.user outlet = check_user_is_active_in_outlet( user, outlet_id=kwargs.get('outlet_id')) return Promotion.objects.filter(outlet=outlet, is_approved=False)
def resolve_outlet_promotions(self, info, **kwargs): user = info.context.user outlet = check_user_is_active_in_outlet( user, outlet_id=kwargs.get('outlet_id')) return Promotion.objects.filter(outlet=outlet)