Пример #1
0
    def default_request_refund(self, data):
        """Requests the refund for the current shipment record
        and returns the response.
        """
        Shipment = Pool().get('stock.shipment.out')

        shipments = Shipment.browse(Transaction().context['active_ids'])

        # PICNumber is the argument name expected by endicia in API,
        # so its better to use the same name here for better understanding
        pic_numbers = []
        for shipment in shipments:
            if not (
                shipment.carrier and
                shipment.carrier.carrier_cost_method == 'endicia'
            ):
                self.raise_user_error('wrong_carrier')

            if shipment.tracking_number:
                pic_numbers.append(shipment.tracking_number.tracking_number)

        test = shipment.carrier.endicia_is_test and 'Y' or 'N'

        refund_request = RefundRequestAPI(
            pic_numbers=pic_numbers,
            accountid=shipment.carrier.endicia_account_id,
            requesterid=shipment.carrier.endicia_requester_id,
            passphrase=shipment.carrier.endicia_passphrase,
            test=test,
        )
        try:
            response = refund_request.send_request()
        except RequestError, error:
            self.raise_user_error('error_label', error_args=(error.message,))
    def _request_refund(self, data):
        """Requests the refund for the current shipment record 
        and returns the response.
        """
        res = data['form']
        company_obj = self.pool.get('company.company')
        shipment_record_obj = self.pool.get('shipment.record')
        shipment_record = shipment_record_obj.browse(data['id'])
        # Getting the api credentials to be used in refund request generation
        # endicia credentials are in the format : 
        # (account_id, requester_id, passphrase, is_test)
        endicia_credentials = company_obj.get_endicia_credentials()
        pic_number = shipment_record.tracking_number

        test = endicia_credentials.usps_test and 'Y' or 'N'

        refund_request = RefundRequestAPI(
            pic_number=pic_number,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=test,
            )
        response = refund_request.send_request()
        result = objectify_response(response)
        if str(result.RefundList.PICNumber.IsApproved) == 'YES':
            refund_approved = True
            # If refund is approved, then set the state of record 
            # as cancel/refund
            shipment_record_obj.write(data['id'], {'state': 'cancel'})
        else:
            refund_approved = False
        res['refund_status'] = str(result.RefundList.PICNumber.ErrorMsg)
        res['refund_approved'] = refund_approved
        return res
Пример #3
0
    def default_request_refund(self, data):
        """Requests the refund for the current shipment record
        and returns the response.
        """
        Shipment = Pool().get('stock.shipment.out')

        shipments = Shipment.browse(Transaction().context['active_ids'])

        # PICNumber is the argument name expected by endicia in API,
        # so its better to use the same name here for better understanding
        pic_numbers = []
        for shipment in shipments:
            if not (shipment.carrier
                    and shipment.carrier.carrier_cost_method == 'endicia'):
                self.raise_user_error('wrong_carrier')

            pic_numbers.append(shipment.tracking_number)

        test = shipment.carrier.endicia_is_test and 'Y' or 'N'

        refund_request = RefundRequestAPI(
            pic_numbers=pic_numbers,
            accountid=shipment.carrier.endicia_account_id,
            requesterid=shipment.carrier.endicia_requester_id,
            passphrase=shipment.carrier.endicia_passphrase,
            test=test,
        )
        try:
            response = refund_request.send_request()
        except RequestError, error:
            self.raise_user_error('error_label', error_args=(error, ))
Пример #4
0
 def test0050_refund_request(self):
     refund_request = RefundRequestAPI(
         pic_numbers=[pic_number],
         requesterid=REQUESTER_ID,
         accountid=ACCOUNT_ID,
         passphrase=PASSPHRASE,
         test='Y',
     )
     print refund_request.to_xml()
     response = refund_request.send_request()
     print objectify_response(response)
Пример #5
0
 def test0050_refund_request(self):
     refund_request = RefundRequestAPI(
         pic_number=pic_number,
         requesterid=REQUESTER_ID,
         accountid=ACCOUNT_ID,
         passphrase=PASSPHRASE,
         test='Y',
     )
     print refund_request.to_xml()
     response = refund_request.send_request()
     print objectify_response(response)
Пример #6
0
    def default_request_refund(self, data):
        """Requests the refund for the current shipment record
        and returns the response.
        """
        Shipment = Pool().get('stock.shipment.out')
        Company = Pool().get('company.company')

        # Getting the api credentials to be used in refund request generation
        # endicia credentials are in the format :
        # (account_id, requester_id, passphrase, is_test)
        company = Transaction().context.get('company')
        endicia_credentials = Company(company).get_endicia_credentials()

        try:
            shipment, = Shipment.browse(Transaction().context['active_ids'])
        except ValueError:
            self.raise_user_error(
                'This wizard can be called for only one shipment at a time'
            )

        if not shipment.carrier.carrier_cost_method == 'endicia':
            self.raise_user_error('wrong_carrier')

        # PICNumber is the argument name expected by endicia in API,
        # so its better to use the same name here for better understanding
        pic_number = shipment.tracking_number

        test = endicia_credentials.usps_test and 'Y' or 'N'

        refund_request = RefundRequestAPI(
            pic_number=pic_number,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=test,
        )
        response = refund_request.send_request()
        result = objectify_response(response)
        if str(result.RefundList.PICNumber.IsApproved) == 'YES':
            refund_approved = True
            # If refund is approved, then set the state of record
            # as cancel/refund
            shipment.__class__.write(
                [shipment], {'endicia_refunded': True}
            )
        else:
            refund_approved = False
        default = {
            'refund_status': unicode(result.RefundList.PICNumber.ErrorMsg),
            'refund_approved': refund_approved
        }
        return default
Пример #7
0
    def refund_request(self, cr, uid, omni, package, context=None):
        """
        Cancels the current shipment and refunds the cost.
        """
        # Getting the api credentials to be used in refund request generation
        # endicia credentials are in the format :
        # (account_id, requester_id, passphrase, is_test)
        package_obj = self.pool.get('stock.out.package')
        omni_obj = self.pool.get('omniship')
        endicia_credentials = omni_obj.get_endicia_credentials(
            cr, uid, omni, context)
        if not endicia_credentials[0] or not endicia_credentials[1] or \
            not endicia_credentials[2]:
            raise osv.except_osv(('Error : '), (
                "Please check the account settings for Endicia account.\nSome details may be missing."
            ))

        pic_number = package.tracking_number

        if endicia_credentials[3]:
            test = 'Y'
        else:
            test = 'N'

        refund_request = RefundRequestAPI(
            pic_number=pic_number,
            accountid=endicia_credentials[0],
            requesterid=endicia_credentials[1],
            passphrase=endicia_credentials[2],
            test=test,
        )

        response = refund_request.send_request()
        result = parse_response(response, refund_request.namespace)

        if result['IsApproved'] == 'YES':
            refund_approved = True
        else:
            refund_approved = False

        package_obj.write(cr,
                          uid,
                          package.id, {
                              'refund_status': result['ErrorMsg'],
                              'refund_approved': refund_approved,
                          },
                          context=context)

        return True
    def default_request_refund(self, data):
        """Requests the refund for the current shipment record
        and returns the response.
        """
        Shipment = Pool().get('stock.shipment.out')
        Company = Pool().get('company.company')

        # Getting the api credentials to be used in refund request generation
        # endicia credentials are in the format :
        # (account_id, requester_id, passphrase, is_test)
        company = Transaction().context.get('company')
        endicia_credentials = Company(company).get_endicia_credentials()

        try:
            shipment, = Shipment.browse(Transaction().context['active_ids'])
        except ValueError:
            self.raise_user_error(
                'This wizard can be called for only one shipment at a time')

        if not shipment.carrier.carrier_cost_method == 'endicia':
            self.raise_user_error('wrong_carrier')

        # PICNumber is the argument name expected by endicia in API,
        # so its better to use the same name here for better understanding
        pic_number = shipment.tracking_number

        test = endicia_credentials.usps_test and 'Y' or 'N'

        refund_request = RefundRequestAPI(
            pic_number=pic_number,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=test,
        )
        response = refund_request.send_request()
        result = objectify_response(response)
        if str(result.RefundList.PICNumber.IsApproved) == 'YES':
            refund_approved = True
            # If refund is approved, then set the state of record
            # as cancel/refund
            shipment.__class__.write([shipment], {'endicia_refunded': True})
        else:
            refund_approved = False
        default = {
            'refund_status': unicode(result.RefundList.PICNumber.ErrorMsg),
            'refund_approved': refund_approved
        }
        return default
Пример #9
0
    def refund_request(self, cr, uid, omni, package, context=None):
        """
        Cancels the current shipment and refunds the cost.
        """
        # Getting the api credentials to be used in refund request generation
        # endicia credentials are in the format : 
        # (account_id, requester_id, passphrase, is_test)
	package_obj = self.pool.get('stock.out.package')
	omni_obj = self.pool.get('omniship')
        endicia_credentials = omni_obj.get_endicia_credentials(
                                                cr,
                                                uid,
						omni,
                                                context)
        if not endicia_credentials[0] or not endicia_credentials[1] or \
            not endicia_credentials[2]:
            raise osv.except_osv(('Error : '),
                ("Please check the account settings for Endicia account.\nSome details may be missing."))

        pic_number = package.tracking_number

        if endicia_credentials[3]:
            test = 'Y'
        else:
            test = 'N'

        refund_request = RefundRequestAPI(
            pic_number=pic_number,
            accountid=endicia_credentials[0],
            requesterid=endicia_credentials[1],
            passphrase=endicia_credentials[2],
            test=test,
        )

        response = refund_request.send_request()
        result = parse_response(response, refund_request.namespace)

        if result['IsApproved'] == 'YES':
            refund_approved = True
        else:
            refund_approved = False

        package_obj.write(cr, uid, package.id, {
                    'refund_status': result['ErrorMsg'], 
                    'refund_approved': refund_approved, 
                    }, context=context)

        return True
Пример #10
0
    def default_request_refund(self, data):
        """Requests the refund for the current shipment record
        and returns the response.
        """
        Shipment = Pool().get('stock.shipment.out')
        EndiciaConfiguration = Pool().get('endicia.configuration')

        # Getting the api credentials to be used in refund request generation
        # endicia credentials are in the format :
        # (account_id, requester_id, passphrase, is_test)
        endicia_credentials = EndiciaConfiguration(1).get_endicia_credentials()

        shipments = Shipment.browse(Transaction().context['active_ids'])

        # PICNumber is the argument name expected by endicia in API,
        # so its better to use the same name here for better understanding
        pic_numbers = []
        for shipment in shipments:
            if not (
                shipment.carrier and
                shipment.carrier.carrier_cost_method == 'endicia'
            ):
                self.raise_user_error('wrong_carrier')

            pic_numbers.append(shipment.tracking_number)

        test = endicia_credentials.is_test and 'Y' or 'N'

        refund_request = RefundRequestAPI(
            pic_numbers=pic_numbers,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=test,
        )
        try:
            response = refund_request.send_request()
        except RequestError, error:
            self.raise_user_error('error_label', error_args=(error,))
Пример #11
0
response = calculate_postage_request.send_request()
print response
print 'calculate', objectify_response(response).PostagePrice.get('TotalAmount')

#
#Refund Request API
#
refund_request = RefundRequestAPI(
                               pic_number=pic_number,
                               requesterid=REQUESTER_ID,
                               accountid=ACCOUNT_ID,
                               passphrase=PASSPHRASE,
                               test='Y',                                    
                            )
print refund_request.to_xml()
response = refund_request.send_request()
print objectify_response(response)


#
#SCAN Request API
#
scan_request = SCANFormAPI(
                               pic_number=pic_number,
                               requesterid=REQUESTER_ID,
                               accountid=ACCOUNT_ID,
                               passphrase=PASSPHRASE,
                               test='Y',                                    
                            )
print scan_request.to_xml()
response = scan_request.send_request()