def set_addr(self): if self.doc.lead: job_location=webnotes.conn.sql("select name,address_type from `tabAddress` where lead='%s'"%(self.doc.lead),as_list=1) if job_location: for address in job_location: if address[1]=='Job Location': self.doc.customer_address=address[0] self.doc.address_display=get_address_display(self.doc.customer_address) else: self.doc.customer_address=address[0] self.doc.address_display=get_address_display(self.doc.customer_address) return self.doc.address_display
def get_cust_addr(self): from utilities.transaction_base import get_default_address, get_address_display res = sql("select customer_name from `tabCustomer` where name = '%s'" % self.doc.customer) address_display = None customer_address = get_default_address("customer", self.doc.customer) if customer_address: address_display = get_address_display(customer_address) ret = {"customer_name": res and res[0][0] or "", "customer_address": address_display} return ret
def get_cust_addr(self): from utilities.transaction_base import get_default_address, get_address_display res = webnotes.conn.sql("select customer_name from `tabCustomer` where name = '%s'"%self.doc.customer) address_display = None customer_address = get_default_address("customer", self.doc.customer) if customer_address: address_display = get_address_display(customer_address) ret = { 'customer_name' : res and res[0][0] or '', 'customer_address' : address_display} return ret
def get_cust_addr(self): from utilities.transaction_base import get_default_address, get_address_display res = webnotes.conn.sql("select customer_name from `tabCustomer` where name = '%s'"%self.doc.client_name) address_display = None customer_address = get_default_address("customer", self.doc.client_name) if customer_address: address_display = get_address_display(customer_address) ret = { 'customer_name' : res and res[0][0] or '', 'address_display' : address_display} return ret
def get_supp_addr(self): from utilities.transaction_base import get_default_address, get_address_display res = sql("""select supplier_name from `tabSupplier` where name=%s""", self.doc.supplier) address_display = None supplier_address = get_default_address("customer", self.doc.customer) if supplier_address: address_display = get_address_display(supplier_address) ret = { 'supplier_name' : res and res[0][0] or '', 'supplier_address' : address_display } return ret
def get_supp_addr(self): from utilities.transaction_base import get_default_address, get_address_display res = webnotes.conn.sql("""select supplier_name from `tabSupplier` where name=%s""", self.doc.supplier) address_display = None supplier_address = get_default_address("customer", self.doc.customer) if supplier_address: address_display = get_address_display(supplier_address) ret = { 'supplier_name' : res and res[0][0] or '', 'supplier_address' : address_display } return ret
def get_address_docs(party=None): from webnotes.model.doclist import objectify from utilities.transaction_base import get_address_display if not party: party = get_lead_or_customer() address_docs = objectify(webnotes.conn.sql("""select * from `tabAddress` where `%s`=%s order by name""" % (party.doctype.lower(), "%s"), party.name, as_dict=True, update={"doctype": "Address"})) for address in address_docs: address.display = get_address_display(address.fields) address.display = (address.display).replace("\n", "<br>\n") return address_docs
def get_address_docs(party=None): from webnotes.model.doclist import objectify from utilities.transaction_base import get_address_display if not party: party = get_lead_or_customer() address_docs = objectify(webnotes.conn.sql("""select * from `tabAddress` where `%s`=%s order by name""" % (party.doctype.lower(), "%s"), party.name, as_dict=True, update={"doctype": "Address"})) for address in address_docs: address.display = get_address_display(address.fields) address.display = (address.display).replace("\n", "<br>\n") return address_docs
def update_cart_address(address_fieldname, address_name): from utilities.transaction_base import get_address_display quotation = _get_cart_quotation() address_display = get_address_display(webnotes.doc("Address", address_name).fields) if address_fieldname == "shipping_address_name": quotation.doc.shipping_address_name = address_name quotation.doc.shipping_address = address_display if not quotation.doc.customer_address: address_fieldname == "customer_address" if address_fieldname == "customer_address": quotation.doc.customer_address = address_name quotation.doc.address_display = address_display apply_cart_settings(quotation=quotation) quotation.ignore_permissions = True quotation.save() return get_cart_quotation(quotation.doclist)
def update_cart_address(address_fieldname, address_name): from utilities.transaction_base import get_address_display quotation = _get_cart_quotation() address_display = get_address_display(webnotes.doc("Address", address_name).fields) if address_fieldname == "shipping_address_name": quotation.doc.shipping_address_name = address_name quotation.doc.shipping_address = address_display if not quotation.doc.customer_address: address_fieldname == "customer_address" if address_fieldname == "customer_address": quotation.doc.customer_address = address_name quotation.doc.address_display = address_display apply_cart_settings(quotation=quotation) quotation.ignore_permissions = True quotation.save() return get_cart_quotation(quotation.doclist)
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"]) '''
def make_po(self,args): net_tot=0.00 po=Document('Purchase Order') po.transaction_date=nowdate() po.price_list_currency='INR' po.currency='INR' po.buying_price_list='Standard Buying' po.customer_detail=webnotes.conn.get_value("Customer",{"innoworth_id":(args['Customer Id']).strip()},"name") po.customer_name=webnotes.conn.get_value("Customer",{"innoworth_id":(args['Customer Id']).strip()},"customer_name") if (args['Territory']).strip(): supplier=sql("select name from tabSupplier where territory='"+(args['Territory']).strip()+"'",as_list=1) if len(supplier)>=1: po.supplier=supplier[0][0] po.status='Draft' po.company='InnoWorth' po.conversion_rate=1.00 po.fiscal_year=webnotes.conn.get_value("Global Defaults", None, "current_fiscal_year") po.customer_address_data=webnotes.conn.get_value("Address",{"customer":po.customer_detail},"name") po.customer_address=get_address_display(po.customer_address_data) po.docstatus=0 po.plc_conversion_rate=1 po.save() for data_c in args['Child']: if (data_c['Item Name']).strip() and (data_c['Qty']).strip(): pre_doc=webnotes.conn.sql("select a.parent as parent,ifnull(a.ordered_qty,0) as ordered_qty,a.name as name,a.qty as qty from `tabMaterial Request Item` a ,`tabMaterial Request` b where a.item_code='"+(data_c['Item Name']).strip()+"' and a.parent=b.name and b.docstatus=1 and a.qty<>ifnull(a.ordered_qty,0) and a.qty<>0",as_list=1) item_details=webnotes.conn.sql("select default_warehouse,item_name,stock_uom,description from tabItem where name='"+(data_c['Item Name']).strip()+"'",as_list=1) order_qty=cstr((data_c['Qty']).strip()) i=0 for s in pre_doc: pi_qty=webnotes.conn.sql("select ifnull(sum(qty),0) from `tabPurchase Order Item` where prevdoc_docname='"+pre_doc[i][0]+"' and prevdoc_detail_docname='"+pre_doc[i][2]+"' and docstatus=0",as_list=1) if pi_qty: available_qty=cstr(cint(pre_doc[i][3])-cint(pre_doc[i][1])-cint(pi_qty[0][0])) else: available_qty=cstr(cint(pre_doc[i][3])-cint(pre_doc[i][1])) if cint(available_qty) >= cint(order_qty): child_data=[] child_data.append([(data_c['Item Name']).strip(),order_qty,(args['Required Date']).strip(),pre_doc[i][0],item_details[0][0],item_details[0][1],item_details[0][2],item_details[0][3],pre_doc[i][2],po.name]) value1=self.create_child_po(child_data) net_tot=cstr(flt(net_tot)+flt(value1)) order_qty=0 break; else: child_data=[] if cint(available_qty)>0: child_data.append([(data_c['Item Name']).strip(),available_qty,(args['Required Date']).strip(),pre_doc[i][0],item_details[0][0],item_details[0][1],item_details[0][2],item_details[0][3],pre_doc[i][2],po.name]) value2=self.create_child_po(child_data) net_tot=cstr(flt(net_tot)+flt(value2)) order_qty=cint(order_qty)-cint(available_qty) i=i+1 if cint(order_qty)!=0: child_data=[] child_data.append([(data_c['Item Name']).strip(),order_qty,(args['Required Date']).strip(),item_details[0][0],item_details[0][1],item_details[0][2],item_details[0][3],po.name]) value3=self.create_material_request(child_data) net_tot=cstr(flt(net_tot)+flt(value3)) po_=Document('Purchase Order',po.name) po_.net_total_import=net_tot po_.grand_total_import=net_tot po_.rounded_total=net_tot po_.save() return {"Purchase Order":po.name}
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_}