Skip to Content
Menu
This question has been flagged
3150 Views

Hello guys:

I want to post data to FBR (Federal Board of Revenue). I am using requests.post method. But i am unable to post data. Please help.

This is my method:

@ api.multi 
def post_data_to_fbr ( self , orders):
fbr_url = "https://esp.fbr.gov.pk:8244/FBR/v1/api/Live/PostData"
#Content type must be included in the header
header = { "Content-Type" : "application / json" }
for order in orders:
    order =   self .browse (order) try : if order and order.session_id and
    
        





order.session_id.config_id and order.session_id.config_id.fbr_authorization:
header.update ({ 'Authorization' : order.session_id.config_id.fbr_authorization})

bill_amount = order.amount_total
TAX_AMOUNT = order.amount_tax
sale_amount = order.order amount_tax
inv_num = ''
if order.partner_id: invoice = self .env [ 'account.invoice' ] .search ([ '&' , ( 'partner_id' , '=' , order.partner_id.id) ,(
'state' , '=' , 'open' )] , limit = 1 )
print ( 'inv' , invoice)
if invoice:
inv_num = invoice.number
order_dic = {
"InvoiceNumber" : inv_num ,
"POSID" : order.session_id .config_id.pos_id , "USIN" : "USIN0" , # "DateTime": datetime.datetime.strptime (order.date_order, "% Y-% m-% d% H:% M:% S"). strftime ("% Y-% m-% d% H:% M:% S"), ""TotalBillAmount" : bill_amount ,
"TotalSaleValue" : sale_amount , "TotalTaxCharged" : tax_amount , "PaymentMode" : 1 , "InvoiceType" : 1 , } if order.partner_id: order_dic.update ({ "BuyerName" : order.partner_id.name , "BuyerPhoneNumber " : order.partner_id.mobile , }) pos_order_lines = self .env [ 'pos.order.line' ] .search ([( 'order_id' , '=' ,order.id)]) print




( 'line' , pos_order_lines)
if order.lines:
items_list = []
print ( 'item' , items_list)
total_qty = 0.0
for line in order.lines: total_qty + = line.qty line_dic = { "ItemCode" : line.product_id .default_code , "ItemName" : line.product_id.name , "Quantity" : line.qty , "PCTCode" : line.product_id.pct_code , "TaxRate" : 0.0 ,


"SaleValue" : line.price_unit ,
# "TotalAmount": line.price_subtotal, # "TaxCharged": line.price_subtotal_incl - line.price_subtotal, "InvoiceType" : 1 , "RefUSIN" : "" } items_list.append (line_dic) order_dic .update ({ "Items" : items_list , "TotalQuantity" : total_qty }) print ( 'num' , order_dic [ 'InvoiceNumber' ] , order_dic [ 'DateTime ' ])








order.write ({ 'post_data_fbr' : True, 'invoice_number' : order_dic [ 'InvoiceNumber' ]})
payment_response = requests.post (fbr_url , data = json.dumps (order_dic) , headers = header , verify = False, timeout = 20 )
# payment_response = requests.post (fbr_url, data = json.dumps (order_dic), headers = header)
print ( 'payment' , payment_response) print ( 'res' , payment_response.json ())

r_json = payment_response.json ()
print ( 'r_json' , r_json)
# invoice_number = r_json.get ( 'InvoiceNumber')
invoice_number = order_dic [ 'InvoiceNumber' ]
order.write ({ 'fbr_respone' : r_json , 'post_data_fbr' : True , 'invoice_number' : invoice_number})

except Exception as e:
values ​​= dict (
exception = e ,
traceback = traceback.format_exc () , ) order.write ({ 'fbr_respone'
: values})
Avatar
Discard

did you find any solution ?