def create_file(self): child_data=sql("select item_code,description,sum(qty) as qty,stock_uom,import_rate,sum(import_amount) as import_amount from `tabPurchase Order Item` where parent='"+self.doc.name+"' group by item_code",as_dict=1) html="" j=0 for r in child_data: j=j+1 webnotes.errprint(r) html+=("<tr><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(j)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(r['item_code'])+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(r['description'])+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;text-align:right;'><div>"+cstr(r['qty'])+"</div></td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(r['stock_uom'])+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'><div style='text-align:right'>₹ "+cstr(r['import_rate'])+"</div></td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'><div style='text-align: right'>₹ "+cstr(r['import_amount'])+"</div></td></tr>") tax_html="" tax_data=sql("select description,tax_amount from `tabPurchase Taxes and Charges` where parent='"+self.doc.name+"'",as_dict=1) for tax in tax_data: tax_html+=("<tr><td style='width:50%;'>"+tax['description']+"</td><td style='width:50%;text-align:right;'>₹ "+cstr(tax['tax_amount'])+"</td></tr>") a=html_data({"posting_date":self.doc.transaction_date,"due_date":"","customer_name":self.doc.customer_name,"net_total":cstr(self.doc.net_total_import),"grand_total":cstr(self.doc.grand_total_import),"rounded_total":cstr(self.doc.grand_total_import),"table_data":html,"date_1":"Purchase Order Date","date_2":"","doctype":"Purchase Order","doctype_no":self.doc.name,"company":self.doc.company,"addr_name":"Address","address":self.doc.customer_address,"tax_detail":tax_html}) attach_file(a,[self.doc.name,"Buying/Kirana","Purchase Order"])
def create_dn(self): ''' import urllib.request import json json_dict=[] ''' dn=Document('Delivery Note') dn.customer=self.doc.customer dn.customer_name=webnotes.conn.get_value("Customer",self.doc.customer,"customer_name") dn.company='InnoWorth' dn.conversion_rate=1.00 dn.posting_date=nowdate() dn.posting_time=nowtime() dn.customer_address=webnotes.conn.get_value("Address",{"customer":self.doc.customer},"name") dn.address_display=get_address_display(dn.customer_address) dn.price_list_currency='INR' dn.currency='INR' dn.docstatus=1 dn.status="Submitted" dn.selling_price_list='Standard Selling' dn.fiscal_year=webnotes.conn.get_value("Global Defaults", None, "current_fiscal_year") dn.save() j=0 html="" net_tot=0.00 for s in getlist(self.doclist,"purchase_receipt_details"): j=j+1 dni=Document("Delivery Note Item") dni.item_code=s.item_code dni.item_name=s.item_name dni.description=s.description dni.qty=s.qty dni.docstatus=1 dni.ref_rate=webnotes.conn.get_value("Item Price",{"item_code":dni.item_code,"price_list":"Standard Selling"},"ref_rate") dni.export_rate=webnotes.conn.get_value("Item Price",{"item_code":dni.item_code,"price_list":"Standard Selling"},"ref_rate") dni.export_amount=cstr(flt(s.qty)*flt(dni.ref_rate)) net_tot=cstr(flt(net_tot)+flt(dni.export_amount)) dni.warehouse=s.warehouse dni.stock_uom=s.uom dni.serial_no=s.serial_no dni.parent=dn.name dni.save() update_bin=("update tabBin set actual_qty=actual_qty-"+cstr(dni.qty)+" and projected_qty=projected_qty-"+cstr(dni.qty)+" where item_code='"+dni.item_code+"' and warehouse='"+dni.warehouse+"'") html+=("<tr><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(j)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(dni.item_code)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(dni.description)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;text-align:right;'><div>"+cstr(dni.qty)+"</div></td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(dni.stock_uom)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'><div style='text-align:right'>₹ "+cstr(dni.ref_rate)+"</div></td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'><div style='text-align: right'>₹ "+cstr(dni.export_amount)+"</div></td></tr>") stl=Document("Stock Ledger Entry") stl.item_code=s.item_code stl.stock_uom=s.uom stl.serial_no=s.serial_no stl.warehouse=s.warehouse stl.posting_date=nowdate() stl.voucher_type="Delivery Note" stl.voucher_no=dn.name stl.voucher_detail_no=dni.name stl.is_cancelled="No" stl.fiscal_year=webnotes.conn.get_value("Global Defaults", None, "current_fiscal_year") stl.actual_qty=cstr(s.qty) qty=webnotes.conn.sql("select qty_after_transaction from `tabStock Ledger Entry` where item_code='"+s.item_code+"' and warehouse='"+s.warehouse+"' order by name desc limit 1",as_list=1) stl.qty_after_transaction=cstr(flt(qty[0][0])-flt(s.qty)) stl.save() if dni.serial_no: for se in dni.serial_no: update=webnotes.conn.sql("update `tabSerial No` set status='Delivered', warehouse=(select name from tabCustomer where 1=2) where name='"+se+"'") #json_dict.append({"serial_no":se,"supplier_name":self.doc.supplier_name,"item_code":s.item_code}) dn_=Document("Delivery Note",dn.name) dn_.net_total_export=cstr(net_tot) dn_.grand_total_export=cstr(net_tot) dn_.rounded_total_export=cstr(net_tot) a=html_data({"posting_date":datetime.datetime.strptime(nowdate(),'%Y-%m-%d').strftime('%d/%m/%Y'),"due_date":"","customer_name":dn.customer_name,"net_total":dn_.net_total_export,"grand_total":dn_.grand_total_export,"rounded_total":dn_.rounded_total_export,"table_data":html,"date_1":"Posting Date","date_2":"","doctype":"Delivery Note","doctype_no":dn.name,"company":dn.company,"addr_name":"Address","address":dn.address_display,"tax_detail":""}) attach_file(a,[dn.name,"Selling/Kirana","Delivery Note"]) '''