~savoirfairelinux-openerp/openerp-usa/openerp-usa

« back to all changes in this revision

Viewing changes to shipping_api_ups/stock.py

  • Committer: Sinoj Sebastian
  • Date: 2011-12-20 08:13:31 UTC
  • Revision ID: ssebastian@novapointgroup.com-20111220081331-10la9pb56q41n8rd
Updated all modules with latest versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
309
309
                serv_path = parse_url.path
310
310
            else:
311
311
                raise osv.except_osv(_('Unable to find Shipping URL!'),_("Please configure the shipping company with websites.") )
312
 
 
313
312
            conn=httplib.HTTPSConnection(serv,void_port)
314
313
            res=conn.request("POST",serv_path,Request_string)
315
314
            res=conn.getresponse()
359
358
#                            'LargePackageIndicator':"",
360
359
                        'ReferenceNumber':{'BarCodeIndicator':"",'Code':pack_obj.ref1 or "",'Value':""},
361
360
#                            'AdditionalHandling':"",
362
 
#                            'PackageServiceOptions':{'DeliveryConfirmation':{'DCISType':"",'DCISNumber':""},#DeliveryConfirmation
363
 
#                                        'InsuredValue':{'Type':"",'Code':"",'Description':"",
364
 
#                                                'CurrencyCode':"",'MonetaryValue':""
365
 
#                                         },#InsuredValue
 
361
                            'PackageServiceOptions':{#'DeliveryConfirmation':{'DCISType':"",'DCISNumber':""},#DeliveryConfirmation
 
362
                                        'InsuredValue':{#'Type':"",'Code':"",'Description':"",
 
363
                                                #'CurrencyCode':"",
 
364
                                                'MonetaryValue':str(pack_obj.decl_val),
 
365
                                                
 
366
                                         },#InsuredValue
366
367
#                                        'COD':{'CODCode':"",'CODFundsCode':"",
367
368
#                                                'CODAmount':{'CurrencyCode':"",
368
369
#                                                        'MonetaryValue':""
377
378
#                                                'Subject':"",'SubjectCode':""}#EMailMessage
378
379
#                                        },#Notification,
379
380
#                                        'ReturnsFlexibleAccessIndicator':"",
380
 
#                        }#PackageServiceOptions
 
381
                        }#PackageServiceOptions
381
382
                })
382
383
            return ret
383
384
 
506
507
        ShipmentIdentificationNumber=''
507
508
        TrackingNumber=''
508
509
        label_image=''
 
510
        control_log_image=''
509
511
        if response_dic['ShipmentAcceptResponse'][0]['Response'][0]['ResponseStatusCode'] == '1':
510
512
            if len(response_dic['ShipmentAcceptResponse'])>1 and response_dic['ShipmentAcceptResponse'][1].has_key('ShipmentResults'):
511
513
                if len(response_dic['ShipmentAcceptResponse'][1]['ShipmentResults'])>1 and response_dic['ShipmentAcceptResponse'][1]['ShipmentResults'][1].has_key('NegotiatedRates'):
522
524
 
523
525
                    if len(response_dic['ShipmentAcceptResponse'][1]['ShipmentResults'][4]['PackageResults'])>2 and response_dic['ShipmentAcceptResponse'][1]['ShipmentResults'][4]['PackageResults'][2].has_key('LabelImage') :
524
526
                        label_image =response_dic['ShipmentAcceptResponse'][1]['ShipmentResults'][4]['PackageResults'][2]['LabelImage'][1]['GraphicImage']
 
527
                
 
528
                
 
529
                for item in response_dic['ShipmentAcceptResponse'][1]['ShipmentResults']:
 
530
                    if item.has_key('ControlLogReceipt'):
 
531
                        for i in item:
 
532
                            for j in item['ControlLogReceipt']:
 
533
                                #print "Control Log :", item
 
534
                                if j.get('GraphicImage'):
 
535
                                    control_log_image = j['GraphicImage']
 
536
                                    
 
537
                                    
 
538
              
 
539
                
525
540
        if TrackingNumber:
526
541
            tracking_url = pack_obj.pick_id.logis_company.ship_tracking_url
527
542
            if tracking_url:
545
560
            label_image=base64.encodestring(label_from_file.read())
546
561
            label_from_file.close()
547
562
 
 
563
        if control_log_image:
 
564
#            print "contrlo log image : ", control_log_image
 
565
            im_in_raw=base64.decodestring(control_log_image)
 
566
            
 
567
            #path=tempfile.mktemp() + '.gif'
 
568
            file_name = tempfile.mktemp() 
 
569
            path= file_name = '.html'
 
570
            temp=file(path,'wb')
 
571
            temp.write(im_in_raw)
 
572
            temp.close()
 
573
            
 
574
            label_from_file=open(path,'rb')
 
575
            control_log_image=base64.encodestring(label_from_file.read())
 
576
            label_from_file.close()
 
577
            
 
578
            
 
579
 
548
580
        self.pool.get('stock.packages').write(cr,uid,[pack_obj.id],{'tracking_no':TrackingNumber or "",
549
581
                                                                     'shipment_identific_no':ShipmentIdentificationNumber or "",
550
582
                                                                     'negotiated_rates':NegotiatedRates or '',
551
583
                                                                     'logo':label_image,
 
584
                                                                     'control_log_receipt' : control_log_image,
552
585
                                                                     'ship_state':'in_process',
553
586
                                                                     'tracking_url':tracking_url})
554
587
 
1653
1686
                InvoiceLineTotal.appendChild(MonetaryValue)
1654
1687
 
1655
1688
 
1656
 
            ShipmentServiceOptions = doc2.createElement("ShipmentServiceOptions")
1657
 
            Shipment.appendChild(ShipmentServiceOptions)
 
1689
            
1658
1690
            if package_obj.pick_id.sat_delivery:
1659
1691
                SaturdayDelivery = doc2.createElement("SaturdayDelivery")
1660
1692
        #        ptext = doc1.createTextNode(data_for_confirm_request["ShipmentConfirmRequest"]["Shipment"]["ShipmentServiceOptions"]["SaturdayDelivery"])
2442
2474
                ptext = doc1.createTextNode(data_for_confirm_request["ShipmentConfirmRequest"]["Shipment"]["Package"][i]['PackageWeight']["Weight"])
2443
2475
                Weight.appendChild(ptext)
2444
2476
                PackageWeight.appendChild(Weight)
 
2477
                
 
2478
                """     <PackageServiceOptions>
 
2479
                            <InsuredValue>
 
2480
                                <CurrencyCode>USD</CurrencyCode>
 
2481
                                <MonetaryValue>1000</MonetaryValue>
 
2482
                            </InsuredValue>
 
2483
                       </PackageServiceOptions>
 
2484
                       
 
2485
                    """
 
2486
                PackageServiceOptions = doc2.createElement("PackageServiceOptions")
 
2487
                
 
2488
                
 
2489
                InsuredValue = doc2.createElement("InsuredValue")
 
2490
                
 
2491
                CurrencyCode = doc2.createElement("CurrencyCode")
 
2492
                ptext = doc1.createTextNode('USD')
 
2493
                CurrencyCode.appendChild(ptext)
 
2494
                
 
2495
                MonetaryValue = doc2.createElement("MonetaryValue")
 
2496
                ptext = doc1.createTextNode(data_for_confirm_request["ShipmentConfirmRequest"]["Shipment"]["Package"][i]["PackageServiceOptions"]['InsuredValue']['MonetaryValue'])
 
2497
                MonetaryValue.appendChild(ptext)
 
2498
                
 
2499
                
 
2500
                InsuredValue.appendChild(CurrencyCode)
 
2501
                InsuredValue.appendChild(MonetaryValue)
 
2502
                
 
2503
                PackageServiceOptions.appendChild(InsuredValue)
 
2504
                
 
2505
                Package.appendChild(PackageServiceOptions)
 
2506
                
2445
2507
    #            LargePackageIndicator = doc2.createElement("LargePackageIndicator")
2446
2508
    ##            ptext = doc1.createTextNode(data_for_confirm_request["ShipmentConfirmRequest"]["Shipment"]["Package"][i]["LargePackageIndicator"])
2447
2509
    ##            LargePackageIndicator.appendChild(ptext)
2675
2737
 
2676
2738
            request_string=Request_string1+request_string2
2677
2739
 
2678
 
            print request_string
2679
2740
            return request_string
2680
2741
 
2681
2742
 
2762
2823
 
2763
2824
                res=conn.getresponse()
2764
2825
                result = res.read()
2765
 
                print "==============="
2766
 
                print result
2767
 
                print "==============="
2768
2826
                response_dic=xml2dic.main(result)
2769
2827
 
2770
2828