def submit_order_to_mws(order, user, **kwargs):
    if kwargs.get('raw', False):
        return

    # these modules have to be imported here because they rely on loading
    # models from oscar_mws using get_model which are not fully loaded at this
    # point because the receivers module is imported into models.py
    from oscar_mws.fulfillment import gateway
    from oscar_mws.fulfillment.creator import FulfillmentOrderCreator

    order_creator = FulfillmentOrderCreator()
    submitted_orders = order_creator.create_fulfillment_order(order)
    gateway.submit_fulfillment_orders(submitted_orders)

    if not order_creator.errors:
        logger.info(
            _("Successfully submitted {0} orders to Amazon").format(
                len(submitted_orders)
            )
        )
    else:
        for order_id, error in order_creator.errors.iteritems():
            logger.error(
                _("Error submitting order {0} to Amazon: {1}").format(
                    order_id,
                    error
                )
            )
Exemplo n.º 2
0
def submit_order_to_mws(order, user, **kwargs):
    if kwargs.get('raw', False):
        return

    # these modules have to be imported here because they rely on loading
    # models from oscar_mws using get_model which are not fully loaded at this
    # point because the receivers module is imported into models.py
    from oscar_mws.fulfillment import gateway
    from oscar_mws.fulfillment.creator import FulfillmentOrderCreator

    try:
        order_creator = FulfillmentOrderCreator()
    except MwsFulfillmentError:
        logger.error(
            "could not create fulfillment order(s) from order {}".format(
                order.number),
            exc_info=1, extra={'order_number': order.number, 'user': user.id})

    submitted_orders = order_creator.create_fulfillment_order(order)
    gateway.submit_fulfillment_orders(submitted_orders)

    failed_orders = [fo.fulfillment_id
                     for fo in submitted_orders
                     if fo.status == fo.SUBMISSION_FAILED]
    if len(failed_orders) > 0:
        for order_id in failed_orders:
            logger.error(
                _("Error submitting orders {} to Amazon").format(
                    ', '.join(failed_orders)))
    else:
        logger.info(
            _("Successfully submitted {0} orders to Amazon").format(
                ', '.join([fo.fulfillment_id for fo in submitted_orders])))
    def test_sets_order_status_to_submitted_when_successful(self):
        self.create_connection_mock()

        with mock.patch('oscar_mws.fulfillment.gateway.get_merchant_connection') as gmc_mock:
            gmc_mock.return_value = self.connection_mock

            gateway.submit_fulfillment_orders([self.fulfillment_order])
            self.assertEquals(self.fulfillment_order.status,
                                self.fulfillment_order.SUBMITTED)
    def test_sets_order_status_to_failed_with_error(self):
        self.create_connection_mock(side_effect=MWSError())

        with mock.patch('oscar_mws.fulfillment.gateway.get_merchant_connection') as gmc_mock:
            gmc_mock.return_value = self.connection_mock

            gateway.submit_fulfillment_orders([self.fulfillment_order])
            self.assertEquals(self.fulfillment_order.status,
                                self.fulfillment_order.SUBMISSION_FAILED)
Exemplo n.º 5
0
    def test_sets_order_status_to_submitted_when_successful(self):
        with mock.patch('oscar_mws.fulfillment.gateway.get_merchant_connection'
                        ) as gmc_mock:
            gmc_mock.return_value = mock.Mock(
                create_fulfillment_order=mock.Mock())

            gateway.submit_fulfillment_orders([self.fulfillment_order])
            self.assertEquals(self.fulfillment_order.status,
                              self.fulfillment_order.SUBMITTED)
Exemplo n.º 6
0
    def test_sets_order_status_to_failed_with_error(self):
        with mock.patch('oscar_mws.fulfillment.gateway.get_merchant_connection'
                        ) as gmc_mock:
            gmc_mock.return_value = mock.Mock(
                create_fulfillment_order=mock.Mock(side_effect=MWSError()))

            gateway.submit_fulfillment_orders([self.fulfillment_order])
            self.assertEquals(self.fulfillment_order.status,
                              self.fulfillment_order.SUBMISSION_FAILED)
Exemplo n.º 7
0
def submit_order_to_mws(order, user, **kwargs):
    if kwargs.get('raw', False):
        return

    # these modules have to be imported here because they rely on loading
    # models from oscar_mws using get_model which are not fully loaded at this
    # point because the receivers module is imported into models.py
    from oscar_mws.fulfillment import gateway
    from oscar_mws.fulfillment.creator import FulfillmentOrderCreator

    try:
        order_creator = FulfillmentOrderCreator()
    except MwsFulfillmentError:
        logger.error(
            "could not create fulfillment order(s) from order {}".format(
                order.number),
            exc_info=1,
            extra={
                'order_number': order.number,
                'user': user.id
            })

    submitted_orders = order_creator.create_fulfillment_order(order)
    gateway.submit_fulfillment_orders(submitted_orders)

    failed_orders = [
        fo.fulfillment_id for fo in submitted_orders
        if fo.status == fo.SUBMISSION_FAILED
    ]
    if len(failed_orders) > 0:
        for order_id in failed_orders:
            logger.error(
                _("Error submitting orders {} to Amazon").format(
                    ', '.join(failed_orders)))
    else:
        logger.info(
            _("Successfully submitted {0} orders to Amazon").format(', '.join(
                [fo.fulfillment_id for fo in submitted_orders])))
Exemplo n.º 8
0
def submit_order_to_mws(order, user, **kwargs):
    if kwargs.get('raw', False):
        return

    # these modules have to be imported here because they rely on loading
    # models from oscar_mws using get_model which are not fully loaded at this
    # point because the receivers module is imported into models.py
    from oscar_mws.fulfillment import gateway
    from oscar_mws.fulfillment.creator import FulfillmentOrderCreator

    order_creator = FulfillmentOrderCreator()
    submitted_orders = order_creator.create_fulfillment_order(order)
    gateway.submit_fulfillment_orders(submitted_orders)

    if not order_creator.errors:
        logger.info(
            _("Successfully submitted {0} orders to Amazon").format(
                len(submitted_orders)))
    else:
        for order_id, error in order_creator.errors.iteritems():
            logger.error(
                _("Error submitting order {0} to Amazon: {1}").format(
                    order_id, error))