def get_user_cart_for_api(self): user = self.user if user.is_authenticated: profile = ProfileRepo(user=self.user).me if profile is not None: orders = [] cart_total = 0 cart_lines_total = 0 cart_lines = CartLine.objects.filter(profile=profile) shops = Shop.objects.filter( id__in=cart_lines.values('shop_id')) for supplier in Supplier.objects.filter( id__in=shops.values('supplier_id')): order = Order() order.supplier = supplier order.ship_fee = supplier.ship_fee lines_total = 0 for line in cart_lines: if line.shop.supplier == supplier: lines_total = lines_total + (line.quantity * line.shop.price) order.lines_total = lines_total total = lines_total + supplier.ship_fee order.total = total cart_total = cart_total + total cart_lines_total = cart_lines_total + lines_total orders.append(order) return { 'lines': cart_lines, 'orders': orders, 'total': cart_total, 'lines_total': cart_lines_total }
def get_profiles(self, channel_event_id): list1 = self.objects.filter(channel_event_id=channel_event_id) profiles = [] for item in list1: profiles.append( ProfileRepo(user=self.user).get(profile_id=item.profile_id)) return profiles
def __init__(self, user=None): self.user = user self.objects = Accountant.objects self.profile = ProfileRepo(user=user).me try: self.me = self.objects.get(profile=self.profile) except: self.me = None
def add_comment(self, product_id, comment): profile = ProfileRepo(user=self.user).me if profile is not None: product_comment = ProductComment() product_comment.profile = profile product_comment.product = self.objects.get(pk=product_id) product_comment.comment = comment product_comment.save() return product_comment
def __init__(self, user=None): self.user = user self.objects = Shipper.objects self.profile = ProfileRepo(user=self.user).me if self.profile is not None: try: self.me = self.objects.get(profile_id=self.profile.id) except: self.me = None else: self.me = None
def related(self, product_id): product = self.get(product_id=product_id) user = self.user region = None if user is not None: profile = ProfileRepo(user=self.user).me if profile is not None: region = profile.region products = product.related.all() for product in products: product.price = Shop.objects.filter(product_id=product.id).filter( supplier__in=Supplier.objects.filter(region=region)).aggregate( Min('price'))['price__min'] return products
def confirm_order(self, order_id, description): profile = ProfileRepo(user=self.user).me if profile is None: return None order = Order.objects.get(pk=order_id) if order.profile == profile and order.status == OrderStatusEnum.CANCELED: order.status = OrderStatusEnum.CONFIRMED if order.description is None: order.description = '' if description is not None: order.description = order.description+' @ ' + \ order.profile.full_name()+' # تایید مجدد '+PersianCalendar().from_gregorian(datetime.datetime.now())+' : '+str(description) order.save() if order is not None: return order
def get(self, product_id): user = self.user region = None if user is not None: profile = ProfileRepo(user=self.user).me if profile is not None: region = profile.region try: product = self.objects.get(pk=product_id) product.category = CategoryRepo(user=user).get( category_id=product.category_id) product.price = Shop.objects.filter(product_id=product.id).filter( supplier__in=Supplier.objects.filter(region=region)).aggregate( Min('price'))['price__min'] except ObjectDoesNotExist: product = None return product
def list(self, category_id=0): user = self.user region = None if user is not None: profile = ProfileRepo(user=self.user).me if profile is not None: region = profile.region if category_id == 0: return [] products = self.objects.filter( category_id=category_id).order_by('priority') for product in products: product.price = Shop.objects.filter(product_id=product.id).filter( supplier__in=Supplier.objects.filter(region=region)).aggregate( Min('price'))['price__min'] return products
def add(self, name, category_id, unit_name=None): user = self.user product = Product(name=name, category_id=category_id) default_unit = ProductUnitRepo(user=self.user).get_by_name( name=unit_name) if ProductUnitRepo(user=self.user).get_by_name( name=unit_name) is not None else ProductUnitRepo( user=self.user).get_default() if user.has_perm(f'{APP_NAME}.add_product'): if category_id == 0: return None else: product.category = CategoryRepo(user=user).get( category_id=category_id) product.adder = ProfileRepo(user=self.user).me product.save() product.unit_names.add(default_unit) product.save() return product return None
def search(self, search_for): user = self.user region = None if user is not None: profile = ProfileRepo(user=self.user).me if profile is not None: region = profile.region products = self.objects.filter(name__contains=search_for) for product in products: product.price = Shop.objects.filter(product_id=product.id).filter( supplier__in=Supplier.objects.filter(region=region)).aggregate( Min('price'))['price__min'] categories = Category.objects.filter(name__contains=search_for) suppliers = Supplier.objects.filter(name__contains=search_for) return { 'products': products, 'categories': categories, 'suppliers': suppliers }
def __init__(self,user): self.user=user self.profile=ProfileRepo(user=user).me self.objects=RequestService.objects
def __init__(self,user): self.user=user self.profile=ProfileRepo(user=user).me self.objects=Entry.objects
def __init__(self, user): self.objects = OrderLine.objects self.user = user self.profile = ProfileRepo(user=self.user).me
def __init__(self, user=None): self.user = user self.profile = ProfileRepo(user=self.user).me
def __init__(self, user=None): self.objects = PusherChannelEvent.objects self.user = user self.profile = ProfileRepo(user=user).me
def __init__(self, user): self.objects = Order.objects.order_by('-id') self.user = user self.profile = ProfileRepo(user=user).me
def __init__(self, user=None): self.objects = Shop.objects self.user = user self.profile = ProfileRepo(user=user).me
def get_count(self, user): if user.is_authenticated: profile = ProfileRepo(user=self.user).me if profile is not None: return len(CartLine.objects.filter(profile=profile))
def list(self): profile = ProfileRepo(user=self.user).me if profile is not None: return self.objects.filter(contractor=profile)
def __init__(self, user=None): self.objects = Product.objects self.user = user self.profile = ProfileRepo(user=self.user).me self.customer = CustomerRepo(user=self.user).me self.supplier = SupplierRepo(user=self.user).me