Exemplo n.º 1
0
    def make_scanform(self):
        """
        Generate the SCAN Form for bag
        """
        Attachment = Pool().get('ir.attachment')

        if not self.shipments:
            self.raise_user_error('bag_empty')

        pic_numbers = [shipment.tracking_number for shipment in self.shipments]
        test = self.carrier.endicia_is_test and 'Y' or 'N'
        scan_request = SCANFormAPI(
            pic_numbers=pic_numbers,
            accountid=self.carrier.endicia_account_id,
            requesterid=self.carrier.endicia_requester_id,
            passphrase=self.carrier.endicia_passphrase,
            test=test,
        )
        response = scan_request.send_request()
        result = objectify_response(response)
        if not hasattr(result, 'SCANForm'):
            self.raise_user_error('error_scanform',
                                  error_args=(result.ErrorMsg, ))
        else:
            self.submission_id = str(result.SubmissionID)
            self.save()
            Attachment.create([{
                'name':
                'SCAN%s.png' % str(result.SubmissionID),
                'data':
                buffer(base64.decodestring(result.SCANForm.pyval)),
                'resource':
                '%s,%s' % (self.__name__, self.id)
            }])
    def make_scanform(self):
        """
        Generate the SCAN Form for bag
        """
        Attachment = Pool().get('ir.attachment')

        if not self.shipments:
            self.raise_user_error('bag_empty')

        pic_numbers = [shipment.tracking_number for shipment in self.shipments]
        test = self.carrier.endicia_is_test and 'Y' or 'N'
        scan_request = SCANFormAPI(
            pic_numbers=pic_numbers,
            accountid=self.carrier.endicia_account_id,
            requesterid=self.carrier.endicia_requester_id,
            passphrase=self.carrier.endicia_passphrase,
            test=test,
        )
        response = scan_request.send_request()
        result = objectify_response(response)
        if not hasattr(result, 'SCANForm'):
            self.raise_user_error(
                'error_scanform', error_args=(result.ErrorMsg,)
            )
        else:
            self.submission_id = str(result.SubmissionID)
            self.save()
            Attachment.create([{
                'name': 'SCAN%s.png' % str(result.SubmissionID),
                'data': buffer(base64.decodestring(result.SCANForm.pyval)),
                'resource': '%s,%s' % (self.__name__, self.id)
            }])
Exemplo n.º 3
0
    def make_scan_form(self, cr, uid, omni, package, context=None):
        """
        Generate the SCAN Form for the current shipment record
        """
        package_obj = self.pool.get('stock.out.package')
        omni_obj = self.pool.get('omniship')
        # 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 = omni_obj.get_endicia_credentials(
            cr, uid, 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.'''))

        # tracking_no is same as PICNumber
        pic_number = package.tracking_number

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

        scan_request = SCANFormAPI(
            pic_number=pic_number,
            accountid=endicia_credentials[0],
            requesterid=endicia_credentials[1],
            passphrase=endicia_credentials[2],
            test=test,
        )

        response = scan_request.send_request()
        result = parse_response(response, scan_request.namespace)
        scan_form = result.get('SCANForm', None)

        if not scan_form:
            raise osv.except_osv(('Error'), ('"%s"' % result.get('ErrorMsg')))

#TODO: Port this code
        package_ids = package_obj.search(cr,
                                         uid,
                                         [('tracking_no', '=', pic_number)],
                                         context=context)

        label_ids = label_obj.create(
            cr, uid, {
                'name': 'SCAN' + result.get('SubmissionID') + '.gif',
                'label_image': scan_form,
                'shipping_package': package_ids[0]
            })

        self.write(cr, uid, ids, {'scan_form': label_ids})
        return True
Exemplo n.º 4
0
 def test0060_scan_form(self):
     scan_request = SCANFormAPI(
         pic_numbers=[pic_number],
         requesterid=REQUESTER_ID,
         accountid=ACCOUNT_ID,
         passphrase=PASSPHRASE,
         test='Y',
     )
     print scan_request.to_xml()
     response = scan_request.send_request()
     print objectify_response(response)
Exemplo n.º 5
0
 def test0060_scan_form(self):
     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()
     print objectify_response(response)
Exemplo n.º 6
0
    def make_scan_form(self, cr, uid, omni, package, context=None):
        """
        Generate the SCAN Form for the current shipment record
        """
        package_obj = self.pool.get('stock.out.package')
        omni_obj = self.pool.get('omniship')
        # 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 = omni_obj.get_endicia_credentials(
                                                cr,
                                                uid,
                                                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.'''))

        # tracking_no is same as PICNumber
        pic_number = package.tracking_number

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

        scan_request = SCANFormAPI(
            pic_number=pic_number,
            accountid=endicia_credentials[0],
            requesterid=endicia_credentials[1],
            passphrase=endicia_credentials[2],
            test=test,
        )

        response = scan_request.send_request()
        result = parse_response(response, scan_request.namespace)
        scan_form = result.get('SCANForm', None)

        if not scan_form:
            raise osv.except_osv(('Error'), ('"%s"' % result.get('ErrorMsg')))
        

	#TODO: Port this code
        package_ids = package_obj.search(cr, uid,
            [('tracking_no', '=', pic_number)], context=context)

        label_ids = label_obj.create(cr, uid, {
           'name': 'SCAN'+result.get('SubmissionID') + '.gif',
           'label_image': scan_form,
           'shipping_package': package_ids[0]})

        self.write(cr, uid, ids, {'scan_form': label_ids})
        return True
    def default_make_scanform(self, data):
        """
        Generate the SCAN Form for the current shipment record
        """
        Shipment = Pool().get('stock.shipment.out')
        Company = Pool().get('company.company')
        Attachment = Pool().get('ir.attachment')

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

        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')

        pic_number = shipment.tracking_number

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

        scan_request = SCANFormAPI(
            pic_number=pic_number,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=test,
        )
        response = scan_request.send_request()
        result = objectify_response(response)
        if not hasattr(result, 'SCANForm'):
            default['response'] = result.ErrorMsg
        else:
            Attachment.create([{
                'name':
                'SCAN%s.png' % str(result.SubmissionID),
                'data':
                buffer(base64.decodestring(result.SCANForm.pyval)),
                'resource':
                'stock.shipment.out,%s' % shipment.id
            }])
            default['response'] = 'SCAN' + str(result.SubmissionID)
        return default
Exemplo n.º 8
0
    def default_make_scanform(self, data):
        """
        Generate the SCAN Form for the current shipment record
        """
        Shipment = Pool().get('stock.shipment.out')
        Company = Pool().get('company.company')
        Attachment = Pool().get('ir.attachment')

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

        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')

        pic_number = shipment.tracking_number

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

        scan_request = SCANFormAPI(
            pic_number=pic_number,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=test,
        )
        response = scan_request.send_request()
        result = objectify_response(response)
        if not hasattr(result, 'SCANForm'):
            default['response'] = result.ErrorMsg
        else:
            Attachment.create([{
                'name': 'SCAN%s.png' % str(result.SubmissionID),
                'data': buffer(base64.decodestring(result.SCANForm.pyval)),
                'resource': 'stock.shipment.out,%s' % shipment.id
            }])
            default['response'] = 'SCAN' + str(result.SubmissionID)
        return default
    def make_scanform(self):
        """
        Generate the SCAN Form for bag
        """
        EndiciaConfiguration = Pool().get('endicia.configuration')
        Attachment = Pool().get('ir.attachment')

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

        if not self.shipments:
            self.raise_user_error('bag_empty')

        pic_numbers = [shipment.tracking_number for shipment in self.shipments]
        test = endicia_credentials.is_test and 'Y' or 'N'
        scan_request = SCANFormAPI(
            pic_numbers=pic_numbers,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=test,
        )
        response = scan_request.send_request()
        result = objectify_response(response)
        if not hasattr(result, 'SCANForm'):
            self.raise_user_error('error_scanform',
                                  error_args=(result.ErrorMsg, ))
        else:
            self.submission_id = str(result.SubmissionID)
            self.save()
            Attachment.create([{
                'name':
                'SCAN%s.png' % str(result.SubmissionID),
                'data':
                buffer(base64.decodestring(result.SCANForm.pyval)),
                'resource':
                '%s,%s' % (self.__name__, self.id)
            }])
    def make_scanform(self):
        """
        Generate the SCAN Form for bag
        """
        EndiciaConfiguration = Pool().get('endicia.configuration')
        Attachment = Pool().get('ir.attachment')

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

        if not self.shipments:
            self.raise_user_error('bag_empty')

        pic_numbers = [shipment.tracking_number for shipment in self.shipments]
        test = endicia_credentials.is_test and 'Y' or 'N'
        scan_request = SCANFormAPI(
            pic_numbers=pic_numbers,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=test,
        )
        response = scan_request.send_request()
        result = objectify_response(response)
        if not hasattr(result, 'SCANForm'):
            self.raise_user_error(
                'error_scanform', error_args=(result.ErrorMsg,)
            )
        else:
            self.submission_id = str(result.SubmissionID)
            self.save()
            Attachment.create([{
                'name': 'SCAN%s.png' % str(result.SubmissionID),
                'data': buffer(base64.decodestring(result.SCANForm.pyval)),
                'resource': '%s,%s' % (self.__name__, self.id)
            }])
    def close(cls, manifests):
        """
        Generate the SCAN Form for manifest
        """
        Attachment = Pool().get('ir.attachment')

        super(ShippingManifest, cls).close(manifests)
        for manifest in manifests:
            if not manifest.shipments:
                manifest.raise_user_error('manifest_empty')

            if manifest.carrier_cost_method != 'endicia':
                continue

            pic_numbers = [
                shipment.tracking_number.tracking_number
                for shipment in manifest.shipments if shipment.tracking_number
            ]
            test = manifest.carrier.endicia_is_test and 'Y' or 'N'
            scan_request = SCANFormAPI(
                pic_numbers=pic_numbers,
                accountid=manifest.carrier.endicia_account_id,
                requesterid=manifest.carrier.endicia_requester_id,
                passphrase=manifest.carrier.endicia_passphrase,
                test=test,
            )
            response = scan_request.send_request()
            result = objectify_response(response)
            if not hasattr(result, 'SCANForm'):
                manifest.raise_user_error(
                    'error_scanform', error_args=(result.ErrorMsg,)
                )
            else:
                Attachment.create([{
                    'name': 'SCAN%s.png' % str(result.SubmissionID),
                    'data': buffer(base64.decodestring(result.SCANForm.pyval)),
                    'resource': '%s,%s' % (manifest.__name__, manifest.id)
                }])
    def _make_scanform(self, data):
        """
        Generate the SCAN Form for the current shipment record
        """
        res = data['form']
        company_obj = self.pool.get('company.company')
        attachment_obj = self.pool.get('ir.attachment')
        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()
        # tracking_no is same as PICNumber
        pic_number = shipment_record.tracking_number

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

        scan_request = SCANFormAPI(
            pic_number=pic_number,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=test,
        )
        response = scan_request.send_request()
        result = objectify_response(response)
        if not hasattr(result, 'SCANForm'):
            res['response'] = result.ErrorMsg
        else:
            attachment_obj.create({
               'name': 'SCAN' + str(result.SubmissionID),
               'data': str(result.SCANForm),
               'resource': 'shipment.record,%s' % data['id']})
            res['response'] = 'SCAN' + str(result.SubmissionID)
        return res
Exemplo n.º 13
0
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()
print objectify_response(response)