Ejemplo 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)
            }])
Ejemplo n.º 2
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
Ejemplo n.º 3
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)
    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)
            }])