def do_ship(self, order_id, description=''): shipper = ShipperRepo(user=self.user).me if shipper is None: return None order = OrderRepo(user=self.user).get(order_id=order_id) if order.status == OrderStatusEnum.PACKED: if description is not None: order.description += '<br> & ' + \ shipper.title+' : '+description order.ship_date = datetime.datetime.now() order.status = OrderStatusEnum.SHIPPED order.shipper = shipper order.save() if order is not None: NotificationRepo(user=self.user).add( title=f'سفارش شماره {order.id} ارسال شده است.', url=order.get_absolute_url(), body= f'سفارش شماره {order.id} توسط {order.shipper.title} ارسال شده است.', icon='alarm', profile_id=order.customer.profile.pk, color='success', priority=1) NotificationRepo(user=self.user).add( title=f'سفارش شماره {order.id} ارسال شده است.', url=order.get_absolute_url(), body= f'سفارش شماره {order.id} توسط {order.shipper.title} ارسال شده است.', icon='alarm', profile_id=order.supplier.profile.pk, color='success', priority=1) return order
def do_deliver(self, order_id, description=''): customer = CustomerRepo(user=self.user).me if customer is None: return None order = OrderRepo(user=self.user).get(order_id=order_id) if order.status == OrderStatusEnum.SHIPPED or ( order.status == OrderStatusEnum.PACKED and order.no_ship == True): if description is not None: order.description += '<br> & ' + customer.profile.name( ) + ' : ' + description order.deliver_date = datetime.datetime.now() order.status = OrderStatusEnum.DELIVERED order.save() if order is not None: NotificationRepo(user=self.user).add( title=f'سفارش شماره {order.id} تحویل گرفته شد .', url=order.get_absolute_url(), body=f'سفارش شماره {order.id} تحویل گرفته شد.', icon='alarm', profile_id=order.supplier.profile.pk, color='success', priority=1) return order
def do_pack(self, order_id, description, count_of_packs=1): profile = self.profile if profile is None: return None order = self.objects.get(pk=order_id) if order.supplier.profile == profile and ( order.status == OrderStatusEnum.PACKING or order.status == OrderStatusEnum.ACCEPTED): order.count_of_packs = count_of_packs if order.description is None: order.description = '' if description is not None: order.description+='<br> & ' + \ order.supplier.title+' : '+str(description) order.pack_date = datetime.datetime.now() order.status = OrderStatusEnum.PACKED order.save() if not order.no_ship: # MyPusherChannel(user=self.user).pack(order_id=order.id,region_id=order.supplier.region,count_of_packs=order.count_of_packs) NotificationRepo(user=self.user).add( title=f'سفارش شماره {order.id} بسته بندی شده است.', url=order.get_absolute_url(), body= f'سفارش شماره {order.id} توسط {order.supplier.title} در {order.count_of_packs} بسته آماده ارسال می باشد.', icon='alarm', profile_id=order.customer.profile.pk, color='success', priority=1) if order is not None: return order
def add_notification_to_profiles(self, channel_event, message): profile_channel_event_repo = ProfileChannelEventRepo(user=self.user) for profile in profile_channel_event_repo.get_profiles( channel_event_id=channel_event.id): NotificationRepo(user=self.user).add(profile.id, title=message['title'], url=message['link'], color=message['color'], icon=message['icon'], body=message['body'])
def notifications(self, request, notification_id=None): user = request.user context = getContext(request=request) if notification_id is None: notifications_seen = NotificationRepo(user=user).list_seen() notifications_unseen = NotificationRepo(user=user).list_unseen() # for notification in notifications_seen: # if notification.seen: # notification.color='scecondary' context['notifications_seen'] = notifications_seen context['notifications_unseen'] = notifications_unseen else: context['notification'] = NotificationRepo(user=user).get( notification_id=notification_id) context['notifications_s'] = json.dumps( NotificationSerializer( NotificationRepo(user=request.user).list_unseen(), many=True).data) return render(request, TEMPLATE_ROOT_DASHBOARD + 'notifications.html', context)
def submit(self, address, description=None, customer_id=None, no_ship=False, supplier_id=0): user = self.user if customer_id is None: customer = CustomerRepo(user=self.user).me else: customer = CustomerRepo(user=self.user).get( customer_id=customer_id) if customer is not None: cart_lines = self.objects.filter(customer=customer) shops = ShopRepo(user=self.user).get_by_cart(cart_lines=cart_lines) orders = [] if supplier_id == 0: suppliers = Supplier.objects.filter( id__in=shops.values('supplier_id')) else: suppliers = [ SupplierRepo(user=self.user).get(supplier_id=supplier_id) ] for supplier in suppliers: order = Order() order.supplier_id = supplier.id order.customer = customer if no_ship: order.ship_fee = 0 else: order.ship_fee = supplier.ship_fee order.status = OrderStatusEnum.CONFIRMED order.description = description order.address = address order.no_ship = no_ship order.order_date = datetime.datetime.now() order.save() if order is not None: orders.append(order) for cart_line in cart_lines: if cart_line.shop.supplier == supplier: order_line = OrderLine( order=order, product=cart_line.shop.product, quantity=cart_line.quantity, price=cart_line.shop.price, #product_name=cart_line.shop.product.name, unit_name=cart_line.shop.unit_name) order_line.save() cart_line.delete() # order=OrderRepo(user=self.user).get(order_id=order.pk) # MyPusherChannel(user=self.user).submit(order_id=order.id,total=order.total(),supplier_id=order.supplier.id) NotificationRepo(user=self.user).add( title='سفارش تایید شده', body=f'سفارش تایید شده به مبلغ {order.total()} تومان', url=order.get_absolute_url(), icon='alarm', profile_id=order.supplier.profile.pk, color='danger', priority=1) ProfileTransactionRepo(user=self.user).add( from_profile_id=order.supplier.id, to_profile_id=order.customer.id, title=f'فاکتور شماره {order.id}', amount=order.total(), cash_type='', description='description') return orders
def getContext(request): user = request.user context = {} context['TEMPLATE_ROOT'] = TEMPLATE_ROOT context['CURRENCY'] = CURRENCY context['links'] = LinkRepo(user=user).list_for_home() context['social_links'] = SocialLinkRepo().list_for_home() if user.is_authenticated: profile = ProfileRepo(user=user).me context['profile'] = profile context['notifications_s'] = json.dumps( NotificationSerializer( NotificationRepo(user=request.user).list_unseen(), many=True).data) context['notifications_count'] = NotificationRepo(user=user).count profiles = ProfileRepo(user=user).list_by_user(user=user) if profile is not None: context['profiles'] = profiles.exclude(pk=profile.pk) if PUSHER_IS_ENABLE: my_channel_events = PusherChannelEventRepo( user=user).my_channel_events() my_channel_events_s = PusherChannelEventSerializer( my_channel_events, many=True).data context['my_channel_events_s'] = json.dumps(my_channel_events_s) else: context['profile'] = None context['profiles'] = None context['my_channel_events_s'] = '[]' context['notifications_s'] = '[]' main_pic_repo = MainPicRepo() link_repo = LinkRepo() parameter_repo = ParameterRepo(user=user) context['theme_color'] = parameter_repo.get( ParametersEnum.THEME_COLOR).value context['PUSHER_IS_ENABLE'] = PUSHER_IS_ENABLE context['app'] = { 'nav_items': link_repo.get_nav_items(), 'about_us_short': parameter_repo.get(ParametersEnum.ABOUT_US_SHORT), 'GOOGLE_SEARCH_CONSOLE_TAG': parameter_repo.get(ParametersEnum.GOOGLE_SEARCH_CONSOLE_TAG), 'NAV_TEXT_COLOR': parameter_repo.get(ParametersEnum.NAV_TEXT_COLOR), 'slogan': parameter_repo.get(ParametersEnum.SLOGAN), 'logo': main_pic_repo.get(name=MainPicEnum.LOGO), 'favicon': main_pic_repo.get(name=MainPicEnum.FAVICON), 'loading': main_pic_repo.get(name=MainPicEnum.LOADING), 'pretitle': parameter_repo.get(ParametersEnum.PRE_TILTE), 'title': parameter_repo.get(ParametersEnum.TITLE), 'address': parameter_repo.get(ParametersEnum.ADDRESS), 'mobile': parameter_repo.get(ParametersEnum.MOBILE), 'email': parameter_repo.get(ParametersEnum.EMAIL), 'tel': parameter_repo.get(ParametersEnum.TEL), 'url': parameter_repo.get(ParametersEnum.URL), 'meta_data_items': MetaDataRepo().list_for_home(), 'our_team_title': OurTeamRepo(user=user).get_title(), 'our_team_link': OurTeamRepo(user=user).get_link(), } context['SITE_URL'] = settings.SITE_URL context['MEDIA_URL'] = settings.MEDIA_URL context['ADMIN_URL'] = settings.ADMIN_URL context['DEBUG'] = settings.DEBUG context['APP_NAME'] = APP_NAME # context['current_profile']=ProfileRepo.get_by_user() context['add_tag_form'] = AddTagForm() #leoData context['search_form'] = SearchForm() return context