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"])
		'''
Beispiel #2
0
	def make_so(self,args):
		# coding: utf-8
		net_tot=0.00
		so=Document('Sales Order')
                so.transaction_date=nowdate()
                so.price_list_currency='INR'
                so.currency='INR'
                so.selling_price_list='Standard Selling'
                so.customer=webnotes.conn.get_value("Customer",{"innoworth_id":(args['Customer Id']).strip()},"name")
                so.customer_name=webnotes.conn.get_value("Customer",{"innoworth_id":(args['Customer Id']).strip()},"customer_name")
                so.delivery_date=(args['Required Date']).strip()
                so.company='InnoWorth'
                so.conversion_rate=1.00
                so.customer_group='Individual'
                if (args['Territory']).strip():
                	so.territory=(args['Territory']).strip()
			so.charge=webnotes.conn.get_value("Applicable Territory",{"territory":so.territory},"parent")
                so.fiscal_year=webnotes.conn.get_value("Global Defaults", None, "current_fiscal_year")
                so.customer_address=webnotes.conn.get_value("Address",{"customer":so.customer},"name")
		so.address_display=get_address_display(so.customer_address)
                so.contact_person=webnotes.conn.get_value("Contact",{"customer":so.customer},"name")
                so.docstatus=1
                so.status='Submitted'
                so.plc_conversion_rate=1
                so.save()
                html=""
		sr=0
		item_list=[]
                for j in args['Child']:
				sr=sr+1
                                soi=Document('Sales Order Item')
                                soi.item_code=(j['Item Name']).strip()
                                soi.qty=(j['Qty']).strip()
				item_details=webnotes.conn.sql("select default_warehouse,item_name,stock_uom,description from tabItem where name='"+(j['Item Name']).strip()+"'",as_list=1)
                                soi.reserved_warehouse=item_details[0][0]
                                soi.item_name=item_details[0][1]                             
                                soi.stock_uom=item_details[0][2]
                                soi.description=item_details[0][3]
                                rate=webnotes.conn.sql("select ref_rate from `tabItem Price` where price_list='Standard Selling' and item_code='"+(j['Item Name']).strip()+"'",as_list=1)
                                if rate:
                                        soi.ref_rate=rate[0][0]
                                        soi.export_rate=rate[0][0]
                                else:
                                        soi.ref_rate=1
                                        soi.export_rate=1
                                soi.export_amount=cstr(flt(soi.ref_rate)*flt((j['Qty']).strip()))
                                item_list.append({"item_code":soi.item_code,"export_amt":soi.export_amount})
                                net_tot=cstr(flt(net_tot)+flt(soi.export_amount))
                                soi.parentfield='sales_order_details'
                                soi.parenttype='Sales Order'
                                soi.docstatus=1
                                soi.parent=so.name
                                soi.save(new=1)
                                html+=("<tr><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(sr)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(soi.item_code)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(soi.description)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;text-align:right;'><div>"+cstr(soi.qty)+"</div></td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(soi.stock_uom)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'><div style='text-align:right'>₹ "+cstr(soi.ref_rate)+"</div></td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'><div style='text-align: right'>₹ "+cstr(soi.export_amount)+"</div></td></tr>")
                                data=[]
                                data.append({"item_code":soi.item_code,"so_qty":soi.qty,"proj_qty":(0-flt(soi.qty)),"warehouse":soi.reserved_warehouse,"bin_iqty":"","bin_pqty":"Bin.projected_qty","type":"so"})
                                self.update_bin(data)
		tax_total=0.00
		if so.charge:
			tax_total=self.create_tax(so.charge,so.name,item_list,'Sales Order','Sales Taxes and Charges',net_tot)
                so_=Document("Sales Order",so.name)
                so_.net_total_export=net_tot	
		so_.other_charges_total_export=cstr(tax_total)
                so_.grand_total_export=cstr(flt(so_.net_total_export)+flt(so_.other_charges_total_export))
                so_.rounded_total_export=cstr(round(flt(so_.grand_total_export)))
                so_.save()
                a=html_data({"posting_date":datetime.datetime.strptime(nowdate(),'%Y-%m-%d').strftime('%d/%m/%Y'),"due_date":datetime.datetime.strptime(so.delivery_date,'%Y-%m-%d').strftime('%d/%m/%Y'),"customer_name":so.customer_name,"net_total":net_tot,"grand_total":net_tot,"rounded_total":net_tot,"table_data":html,"date_1":"Sales Order Date","date_2":"Expected Delivery Date","doctype":"Sales Order","doctype_no":so.name,"company":so.company,"addr_name":"Customer Address","address":so.address_display,"tax_detail":""})
                file_path_=attach_file(a,[so.name,"Selling/Kirana","Sales Order"])
                return {"Sales Order":so.name,"File Copy":file_path_}