def __parse_invoice(self, data): factor = data.Factor_Products.all().first() if not factor: raise SkipItemException( f'No Factor found for FactorPost: {data.ID}') invoice = Invoice.objects.filter(old_id=factor.ID).first() if not invoice: raise SkipItemException( f'No invoice found for Factor: {factor.ID}') return invoice
def parse_data(self, data): invoice = Invoice.objects.filter(old_id=data.ID).first() coupon_id = data.FK_Coupon.id if data.FK_Coupon else None if not invoice: raise SkipItemException( f'Invoice with id: {data.ID} does not exists!') if not coupon_id: raise SkipItemException('Factor has no coupon assigned to') coupon_price = data.DiscountRate return { 'invoice': invoice, 'coupon_id': coupon_id, 'price_applied': coupon_price, }
def __parse_transaction(self, data): order_id = data.OrderId transaction = Transaction.objects.filter(order_number=order_id).first() if not transaction: raise SkipItemException( f'Transaction with order_id: {order_id} does not exists!') return transaction
def __parse_logistic_price(self, data): try: return float(data.PostPrice or 0) except: raise SkipItemException( f'Cannot convert PostPrice to decimal: {data.PostPrice} if factor: {data.ID}' )
def parse_data(self, data): factor = data.Factor_Products.first() if not factor: raise SkipItemException( f'FactorPost {data.ID} has no factor assigned to') if not data.FK_Product: raise SkipItemException(f'FactorPost {data.ID} has no product') cart = Cart.objects.filter(old_id=factor.ID).first() if not cart: raise SkipItemException( f'No cart created base on FactorPost with id {factor.ID}') return { 'cart': cart, 'product': data.FK_Product, 'count': data.ProductCount, 'extra_data': self.__parse_extra_data(data) }
def __parse_product(self, data): if not data.FK_Product: raise SkipItemException( f'No product assiged to FactorPost: {data.ID}') return data.FK_Product
def __parse_user(self, data): if not data.FK_User: raise SkipItemException(f'No user assigned to factor: {data.ID}') return data.FK_User
def __parse_status(self, is_paid): if is_paid: raise SkipItemException( 'This factor is paid, not creating cart form it')
def __parse_user(self, user): if user in self.cart_users: raise SkipItemException(f'User {user} already has a cart') self.cart_users.add(user)