def test_b2b_order_audit(): """ B2BOrder.save_and_log() should save the order's information to an audit model. """ order = B2BOrderFactory.create() assert B2BOrderAudit.objects.count() == 0 order.save_and_log(None) assert B2BOrderAudit.objects.count() == 1 order_audit = B2BOrderAudit.objects.first() assert order_audit.order == order assert order_audit.data_after == { **serialize_model_object(order), "product_version_info": { **serialize_model_object(order.product_version), "product_info": { **serialize_model_object(order.product_version.product), "content_type_string": str(order.product_version.product.content_type), "content_object": serialize_model_object( order.product_version.product.content_object ), }, }, "receipts": [ serialize_model_object(receipt) for receipt in order.b2breceipt_set.all() ], }
def to_dict(self): """ Get a serialized representation of the Order and any attached Basket and Lines """ from ecommerce.api import get_product_version_price_with_discount # should be 0 or 1 coupons, and only one line and product coupon_redemption = self.couponredemption_set.first() line = self.lines.first() return { **serialize_model_object(self), "purchaser_email": self.purchaser.email, "lines": [{ **serialize_model_object(line), "product_version_info": { **serialize_model_object(line.product_version), "product_info": { **serialize_model_object(line.product_version.product), "content_type_string": str(line.product_version.product.content_type), "content_object": serialize_model_object( line.product_version.product.content_object), }, }, } for line in self.lines.all()], "coupons": [{ **serialize_model_object(coupon_redemption.coupon_version.coupon), "coupon_version_info": { **serialize_model_object(coupon_redemption.coupon_version), "payment_version_info": serialize_model_object( coupon_redemption.coupon_version.payment_version), }, } for coupon_redemption in self.couponredemption_set.all()], "run_enrollments": [ enrollment.run.courseware_id for enrollment in self.courserunenrollment_set.all() ], "total_price": str( get_product_version_price_with_discount( coupon_version=coupon_redemption. coupon_version if coupon_redemption is not None else None, product_version=line.product_version, ) if line is not None else ""), "receipts": [ serialize_model_object(receipt) for receipt in self.receipt_set.all() ], }
def to_dict(self): return { **serialize_model_object(self), "username": self.user.username, "full_name": self.user.name, "email": self.user.email, "company_name": self.company.name if self.company else None, }
def to_dict(self): """ Get a serialized representation of the B2BOrder """ return { **serialize_model_object(self), "product_version_info": { **serialize_model_object(self.product_version), "product_info": { **serialize_model_object(self.product_version.product), "content_type_string": str(self.product_version.product.content_type), "content_object": serialize_model_object( self.product_version.product.content_object), }, }, "receipts": [ serialize_model_object(receipt) for receipt in self.b2breceipt_set.all() ], }
def to_dict(self): return serialize_model_object(self)
def to_dict(self): """Serialize anything which would contribute to an audit trail""" return serialize_model_object(self)
def test_order_audit(has_user, has_lines): """ Order.save_and_log() should save the order's information to an audit model. """ coupon_redemption = CouponRedemptionFactory.create() assert str(coupon_redemption ) == "CouponRedemption for order {}, coupon version {}".format( str(coupon_redemption.order), str(coupon_redemption.coupon_version)) order = coupon_redemption.order contents = [CourseRunFactory.create(), ProgramFactory.create()] lines = ([ LineFactory.create(order=order, product_version__product__content_object=content) for content in contents ] if has_lines else []) assert OrderAudit.objects.count() == 0 order.save_and_log(UserFactory.create() if has_user else None) assert OrderAudit.objects.count() == 1 order_audit = OrderAudit.objects.first() assert order_audit.order == order assert order_audit.data_after == { **serialize_model_object(order), "purchaser_email": order.purchaser.email, "lines": [{ **serialize_model_object(line), "product_version_info": { **serialize_model_object(line.product_version), "product_info": { **serialize_model_object(line.product_version.product), "content_type_string": str(line.product_version.product.content_type), "content_object": serialize_model_object( line.product_version.product.content_object), }, }, } for line in lines], "coupons": [{ **serialize_model_object(coupon_redemption.coupon_version.coupon), "coupon_version_info": { **serialize_model_object(coupon_redemption.coupon_version), "payment_version_info": serialize_model_object( coupon_redemption.coupon_version.payment_version), }, } for coupon_redemption in order.couponredemption_set.all()], "run_enrollments": [ enrollment.run.courseware_id for enrollment in order.courserunenrollment_set.all() ], "total_price": str( get_product_version_price_with_discount( product_version=lines[0].product_version, coupon_version=order.couponredemption_set.first(). coupon_version, )) if has_lines else "", "receipts": [ serialize_model_object(receipt) for receipt in order.receipt_set.all() ], }