Beispiel #1
0
    def post(self):
        doer = getTheDoer()
        form = CreateServiceOrderForm()
    
        if form.validate():
            patient = None
            if form.data['patient_id']:
                patient = patientRepo.get(form.data['patient_id'])
            
            service = serviceRepo.get(form.data['service_id'])
            numberOfSessions = form.data['numberOfSessions']

            serviceOffer = None
            if form.data['serviceOffer_id'] is not None:
                serviceOffer = ServiceOffer.query.get(form.data['serviceOffer_id'])

            if patient is None:
                patient = Patient(name=form.data['name'], mobileNumber=form.data['mobileNumber'], createdBy=doer)
                # patientRepo.save(patient)


            payments = None
            discount = form.data['discount']

            if form.data['amount']:
                amount = form.data['amount']
                
                paymentType = PaymentTypes.CASH
                if form.data['paymentType']:
                    paymentType = form.data['paymentType']

                payment = ServicePayment(amount=amount, paymentType=paymentType, createdBy=doer)
                payments = [payment]
            try:
                entity = ServiceOrder(patient=patient, service=service, numberOfSessions=numberOfSessions, 
                    serviceOffer=serviceOffer, payments=payments, createdBy=doer)
                
                # discount the order
                if discount is not None :
                    try:
                        entity.setOrderDiscount(amount=discount, user=doer)
                    except ValueError as err:
                        return unableToProcessResponse([ err.args[0] ])

                serviceOrderRepo.save(entity)
                return createdResponseWithPayload(marshal(entity, serviceOrder_fields))
            except ValueError as err:
                return unableToProcessResponse([ err.args[0] ])

        return unableToProcessResponse(form.errors)
Beispiel #2
0
    def test_refund_state(self):
        
        patient = Patient(name='patient one with  order ', mobileNumber='11111')
        service = Service(name='service for orders x', price=150)
        user = User(name='test user  x', userName='******', password='******')
        
        sessions = None
        payment = ServicePayment(amount=120, paymentType=1)
        order = ServiceOrder(patient=patient,service=service, sessions=sessions, numberOfSessions=5, payments=[payment])
        self.assertEquals(order.totalPayments , 120)

        self.assertTrue(order.refundable)


        
        for session in order.sessions:
            session.arrived(user)
            self.assertTrue(SessionStates.arrived, session.state)

        for session in order.sessions:
            session.start(user)
            self.assertTrue(SessionStates.started, session.state)
            self.assertTrue(session.inTransitionState() )



        for session in order.sessions:
            session.done(user)
            self.assertTrue(SessionStates.done, session.state)
            self.assertFalse(session.inTransitionState() )

        order.refundOrder(amount=120, user=user)


        for session in order.sessions:
            self.assertEquals(SessionStates.refunded, session.state)
            self.assertFalse(session.inTransitionState() )
            self.assertTrue(session.hasState(SessionStates.arrived) )
            self.assertTrue(session.hasState(SessionStates.started) )
            self.assertTrue(session.hasState(SessionStates.done) )

            self.assertTrue(session.hasState(SessionStates.refunded) )
Beispiel #3
0
    def setUp(self):
        service = Service(name="service 1 s", price=100)
        patient = Patient(name="patient 1 z", mobileNumber="121232")
        user = User(password="******", name="user one receive", userName="******")
        refundUser = User(password="******", name="refundUser", userName="******")
        payments = []
        payments.append(ServicePayment(amount=100, paymentType=PaymentTypes.CASH, createdBy=user))
        payments.append(ServicePayment(amount=50, paymentType=PaymentTypes.CASH, createdBy=user))
        payments.append(ServicePayment(amount=50, paymentType=PaymentTypes.CASH, createdBy=user))
        payments.append(ServicePayment(amount=100, paymentType=PaymentTypes.CASH, createdBy=user))
        payments.append(ServicePayment(amount=100, paymentType=PaymentTypes.VISA, createdBy=user))
        serviceOrder = ServiceOrder(service=service, numberOfSessions=10, patient=patient, payments=payments)

        db.session.add(serviceOrder)
        db.session.commit()

        serviceOrder.refundOrder(amount=300, fee=100, user=refundUser, refundReason="no reason !")

        db.session.add(serviceOrder)
        db.session.commit()

        payments = []
        payments.append(ServicePayment(amount=1000, paymentType=PaymentTypes.CASH, createdBy=user))
        payments.append(ServicePayment(amount=500, paymentType=PaymentTypes.VISA, createdBy=user))
        serviceOrder = ServiceOrder(service=service, numberOfSessions=20, patient=patient, payments=payments)
        db.session.add(serviceOrder)
        db.session.commit()

        serviceOrder.refundOrder(amount=1400, fee=100, user=refundUser, refundReason="no reason 22!")

        db.session.add(serviceOrder)
        db.session.commit()
Beispiel #4
0
    def setUp(self):
        service = Service(name='service 1 refund test', price=100)
        patient = Patient(name='patient 1 refund test', mobileNumber="232r3r32r3")
        user = User(name='user 1 ', userName="******", password='******')
        payments = []
        payments.append(ServicePayment(amount=100, paymentType=PaymentTypes.CASH) )
        payments.append(ServicePayment(amount=50, paymentType=PaymentTypes.CASH) )
        payments.append(ServicePayment(amount=50, paymentType=PaymentTypes.CASH) )
        payments.append(ServicePayment(amount=100, paymentType=PaymentTypes.CASH) )
        payments.append(ServicePayment(amount=100, paymentType=PaymentTypes.VISA) )
        serviceOrder = ServiceOrder(service=service, numberOfSessions=10, patient=patient, payments=payments)


        serviceOrder.refundOrder(amount=300, fee=100, user=user);

        db.session.add(serviceOrder)
        db.session.commit()


        payments = []
        payments.append(ServicePayment(amount=1000, paymentType=PaymentTypes.CASH) )
        payments.append(ServicePayment(amount=500, paymentType=PaymentTypes.VISA) )
        serviceOrder = ServiceOrder(service=service, numberOfSessions=20, patient=patient, payments=payments)


        serviceOrder.refundOrder(amount=1000, fee=500, user=user);

        db.session.add(serviceOrder)
        db.session.commit()
Beispiel #5
0
    def setUp(self):
        service = Service(name='service 1 s', price=100)
        patient = Patient(name='patient 1 z', mobileNumber="121232")
        user = User(password='******', name='user one receive', userName='******')
        discountUser = User(password='******', name='discountUser', userName='******')
        payments = []
        payments.append(ServicePayment(amount=100, paymentType=PaymentTypes.CASH, createdBy=user) )
        payments.append(ServicePayment(amount=50, paymentType=PaymentTypes.CASH, createdBy=user) )
        payments.append(ServicePayment(amount=50, paymentType=PaymentTypes.CASH, createdBy=user) )
        payments.append(ServicePayment(amount=100, paymentType=PaymentTypes.CASH, createdBy=user) )
        payments.append(ServicePayment(amount=100, paymentType=PaymentTypes.VISA, createdBy=user) )
        serviceOrder = ServiceOrder(service=service, numberOfSessions=10, patient=patient, payments=payments)
        serviceOrder.setOrderDiscount(amount=500, user=user)

        db.session.add(serviceOrder)
        db.session.commit()

        # serviceOrder.refundOrder(amount=300, fee=100, user= discountUser, refundReason='no reason !')
        
        db.session.add(serviceOrder)
        db.session.commit()

        payments = []
        payments.append(ServicePayment(amount=1000, paymentType=PaymentTypes.CASH, createdBy=user) )
        payments.append(ServicePayment(amount=500, paymentType=PaymentTypes.VISA, createdBy=user) )
        serviceOrder = ServiceOrder(service=service, numberOfSessions=20, patient=patient, payments=payments)

        serviceOrder.setOrderDiscount(amount=500, user=user)

        db.session.add(serviceOrder)
        db.session.commit()

        # serviceOrder.refundOrder(amount=1400, fee=100, user= discountUser, refundReason='no reason 22!')
        
        db.session.add(serviceOrder)
        db.session.commit()