def _add_comments(task, comments_to_import, global_id, assignee, reference): task_detail_text = '' task_comments = comments_to_import.get(global_id) if task_comments: for comment in task_comments: commented_by = comment["created_by"]["name"] comment_text = comment["text"] comment_email = commented_by employee = frappe.db.exists("Employee", {"employee_name": commented_by}) if employee: user = frappe.db.get_value("Employee", employee, "user_id") comment_email = user try: add_comment("Task", task, comment_text, comment_email, commented_by) except Exception as e: frappe.log_error(e) if assignee: task_detail_text = _("This Task was assigned to {0}").format( assignee) + "<br>" task_detail_text += "Reference: " + "<a href=" + (reference) + ">" + ( reference) + "</a>" try: add_comment("Task", task, task_detail_text, frappe.session.user, frappe.session.user_fullname) except Exception as e: frappe.log_error(e)
def add_transaction_comment(self): if not self.is_new(): if self.notes or self.transaction_detailed: add_comment( self.doctype, self.name, self.last_message, self.edited_user, )
def add_transaction_comment(doc): if not doc.is_new(): if doc.last_message: add_comment( doc.doctype, doc.name, doc.last_message, "guest", "guest", )
def add_transaction_comment(self): if not self.is_new(): if self.notes: add_comment( self.doctype, self.name, self.notes, self.edited_user, self.edited_user, )
def make_remove_item_material(reference_doctype, reference_name,delet_item_code, content, comment_email): #frappe.throw(_("{0} need to remove").format(delet_item_code)) child_item_name = check_item_material(delet_item_code,reference_name) if child_item_name: for child_item in child_item_name: if delet_item_code == child_item.get("item_code"): if child_item.get("reserved_qty_at_reserve_warehouse") > 0: frappe.throw(_("Error: Cannot remove selected item ({0}), Item has ({1}) quantity in Reserve Warehouse.<br>Return quantity to Source Warehouse then remove").format(delet_item_code,child_item.get("reserved_qty_at_reserve_warehouse"))) if child_item.get("transferred_qty_to_wip_warehouse") > 0: frappe.throw(_("Error: Cannot remove selected item ({0}), Item has ({1}) quantity in WIP Warehouse.<br>Return quantity to Source Warehouse then remove").format(delet_item_code,child_item.get("transferred_qty_to_wip_warehouse"))) #frappe.delete_doc('Collect Production Item Materials', child_item.get("name")) delete_item_material('Collect Production Item Materials',reference_name,child_item.get("name")) all_item_material = get_all_item_material(reference_name) idx_count = 1 for child_item_old_idx in all_item_material: child_item = frappe.get_doc('Collect Production Item Materials', child_item_old_idx.get("name")) child_item.db_set('idx', idx_count, update_modified=False) idx_count = idx_count + 1 else: frappe.throw(_("Selected item ({0}) not at Material Items").format(delet_item_code)) cpi_update_status(reference_name) add_new_comment = add_comment(reference_doctype, reference_name, content, comment_email) doc = frappe.get_doc('Collect Production Item', reference_name) doc.reload() doc.flags.ignore_validate_update_after_submit = True doc.update_stock_qty() doc.set_bom_material_details() doc.update_cost() doc.save() return add_new_comment
def add_comment_to_patch(reference_name, content): email = frappe.session.user name = frappe.db.get_value("User", frappe.session.user, ["first_name"], as_dict=True).get("first_name") comment = add_comment("Wiki Page Patch", reference_name, content, email, name) comment.timepassed = frappe.utils.pretty_date(comment.creation) return comment
def send_eirsaliye(delivery_note_name): import urllib3 strResult = "" urllib3.disable_warnings() #Remove TLS warning doc = frappe.get_doc("Delivery Note", delivery_note_name) if not doc.eirsaliye_uuid: doc.eirsaliye_uuid = str(uuid.uuid1()) doc.db_update() frappe.db.commit() doc.reload() if doc.yerelbelgeoid: data = validate_eirsaliye(delivery_note_name) if data.get("belgeNo"): return data #Validate the DN fields. validate_delivery_note(doc) if doc.belgeno: #If belgeno field is not empty dctResponse = validate_eirsaliye(doc.name) if dctResponse.get( 'durum' ) != 2: #If durum is not xml error return it back so we should send the DN only if we hasn't sent it or if we had an XML error before. return eirsaliye_settings = frappe.get_all("E Irsaliye Ayarlar", filters={"company": doc.company})[0] settings_doc = frappe.get_doc("E Irsaliye Ayarlar", eirsaliye_settings) validate_settings_doc(settings_doc) set_warehouse_address_doc = frappe.get_doc( "Address", get_default_address("Warehouse", doc.set_warehouse)) set_warehouse_address_doc = set_missing_address_values( set_warehouse_address_doc) validate_address(set_warehouse_address_doc) customer_doc = frappe.get_doc("Customer", doc.customer) validate_customer(customer_doc) customer_address_doc = frappe.get_doc("Address", doc.shipping_address_name) customer_address_doc = set_missing_address_values(customer_address_doc) validate_address(customer_address_doc) doc = set_driver_name(doc) doc.posting_time = format_datetime(str(doc.posting_time), "HH:mm:ss") user = {} user["full_name"] = frappe.get_value("User", frappe.session.user, "full_name") for item in doc.items: eirsaliye_birimi_list = frappe.get_list( "TD EIrsaliye Birim Eslestirme", filters={ "parent": settings_doc.name, "td_birim": item.uom, }, fields=["td_eirsaliye_birimi"]) if len(eirsaliye_birimi_list) == 0: frappe.throw( _("Please set {0} uom in e-Receipt settings for company {1}."). format(item.uom, eirsaliye_settings)) td_eirsaliye_birimi = eirsaliye_birimi_list[0]["td_eirsaliye_birimi"] item.td_eirsaliye_birimi = td_eirsaliye_birimi data_context = { "delivery_note_doc": doc, "settings_doc": settings_doc, "set_warehouse_address_doc": set_warehouse_address_doc, "customer_doc": customer_doc, "customer_address_doc": customer_address_doc, "user": user, } outputText = render_template( data_context, file=settings_doc.xml_data ) # this is where to put args to the template renderer settings_doc.veri = to_base64(outputText) settings_doc.belgeHash = get_hash_md5(outputText) endpoint = settings_doc.test_eirsaliye_url if settings_doc.test_modu else settings_doc.eirsaliye_url settings_doc.password_uncoded = settings_doc.get_password('password') body_context = { "delivery_note_doc": doc, "settings_doc": settings_doc, } body = render_template(body_context, file=settings_doc.xml_body) body = body.encode('utf-8') session = requests.session() session.headers = {"Content-Type": "text/xml; charset=utf-8"} session.headers.update({"Content-Length": str(len(body))}) response = session.post(url=endpoint, data=body, verify=False) xml = response.content #frappe.msgprint(xml) #print("XML CONTENT IS") #print(xml) add_comment(doc.doctype, doc.name, str(xml), doc.modified_by) soup = BeautifulSoup(xml, 'xml') error = soup.find_all('Fault') belgeOid = soup.find_all('belgeOid') if error: faultcode = soup.find('faultcode').getText() faultstring = soup.find('faultstring').getText() #frappe.msgprint(str(faultcode) + " " + str(faultstring)) #strResult = str(faultcode) + " " + str(faultstring) dctResult = { 'result': False, 'description': _("Error Code:{0}. Error Description:{1}").format( faultcode, faultstring) } if belgeOid: msg = soup.find('belgeOid').getText() doc.yerelbelgeoid = msg doc.db_update() frappe.db.commit() doc.reload() #frappe.msgprint(str(msg)) #strResult = str(msg) dctResult = {'result': True, 'description': msg} return dctResult #strResult
def validate_eirsaliye(delivery_note_name): doc = frappe.get_doc("Delivery Note", delivery_note_name) if not doc.yerelbelgeoid and not doc.belgeno: frappe.throw(_("Please send the delivery note first!")) eirsaliye_settings = frappe.get_all("E Irsaliye Ayarlar", filters={"company": doc.company})[0] settings_doc = frappe.get_doc("E Irsaliye Ayarlar", eirsaliye_settings) endpoint = settings_doc.test_eirsaliye_url if settings_doc.test_modu else settings_doc.eirsaliye_url user = settings_doc.user_name password = settings_doc.get_password('password') body_context = { "user": user, "password": password, "td_vergi_no": settings_doc.td_vergi_no, "belgeno": doc.yerelbelgeoid or doc.belgeno, } body = render_template(body_context, file_name="validate_eirsaliye.xml") body = body.encode('utf-8') session = requests.session() session.headers = {"Content-Type": "text/xml; charset=utf-8"} session.headers.update({"Content-Length": str(len(body))}) response = session.post(url=endpoint, data=body, verify=False) xml = response.content soup = BeautifulSoup(xml, 'xml') msg = {} if soup.find_all('belgeOid'): msg["belgeOid"] = soup.find('belgeOid').getText() if soup.find_all('faultstring'): msg["faultstring"] = soup.find('faultstring').getText() if soup.find_all('faultcode'): msg["faultcode"] = soup.find('faultcode').getText() if soup.find_all('aciklama'): msg["aciklama"] = soup.find('aciklama').getText() if soup.find_all('alimTarihi'): msg["alimTarihi"] = soup.find('alimTarihi').getText() if soup.find_all('ettn'): msg["ettn"] = soup.find('ettn').getText() if soup.find_all('belgeNo'): msg["belgeNo"] = soup.find('belgeNo').getText() if soup.find_all('gonderimCevabiDetayi'): msg["gonderimCevabiDetayi"] = soup.find( 'gonderimCevabiDetayi').getText() if soup.find_all('olusturulmaTarihi'): msg["olusturulmaTarihi"] = soup.find('olusturulmaTarihi').getText() if soup.find_all('yanitDetayi'): msg["yanitDetayi"] = soup.find('yanitDetayi').getText() if soup.find_all('durum'): msg["durum"] = soup.find('durum').getText() if soup.find_all('gonderimCevabiKodu'): msg["gonderimCevabiKodu"] = soup.find('gonderimCevabiKodu').getText() if soup.find_all('gonderimDurumu'): msg["gonderimDurumu"] = soup.find('gonderimDurumu').getText() if soup.find_all('yanitDurumu'): msg["yanitDurumu"] = soup.find('yanitDurumu').getText() if soup.find_all('ulastiMi'): msg["ulastiMi"] = soup.find('ulastiMi').getText() if soup.find_all('yenidenGonderilebilirMi'): msg["yenidenGonderilebilirMi"] = soup.find( 'yenidenGonderilebilirMi').getText() if soup.find_all('yerelBelgeOid'): msg["yerelBelgeOid"] = soup.find('yerelBelgeOid').getText() if msg.get("belgeNo") and not doc.belgeno: doc.belgeno = msg.get("belgeNo") if msg.get("durum"): doc.durum = msg.get("durum") if msg.get("yenidenGonderilebilirMi"): doc.yenidengonderilebilirmi = msg.get("yenidenGonderilebilirMi") if msg.get("gonderimCevabiDetayi"): doc.gonderimcevabidetayi = msg.get("gonderimCevabiDetayi") if msg.get("gonderimCevabiKodu"): doc.gonderimCevabiKodu = msg.get("gonderimCevabiKodu") if msg.get("gonderimDurumu"): doc.gonderimdurumu = msg.get("gonderimDurumu") if msg.get("yerelBelgeOid") and not doc.yerelbelgeoid: doc.yerelbelgeoid = msg.get("yerelBelgeOid") doc.db_update() frappe.db.commit() add_comment(doc.doctype, doc.name, _("Durum Kontrol Cevabı: {0}".format(msg)), doc.modified_by) print(_("Durum Kontrol Cevabı: {0}".format(xml))) return { #return(msg) 'result': True, 'description': msg }