def autoname(self): from frappe.model.naming import make_autoname if self.meeting_category=='Cell Meeting': self.name = make_autoname(self.cell + '/' + 'CELL' + 'ATT' + '.####') else: sub=self.meeting_sub[:3].upper() self.name = make_autoname(self.cell + '/' + sub + 'ATT' + '.####')
def autoname(self): supp_master_name = frappe.defaults.get_global_default('supp_master_name') if supp_master_name == 'Supplier Name': self.name = self.supplier_name # self.name = self.supplier_name + '-' + self.company else: self.name = make_autoname(self.naming_series + '.#####')
def autoname(self): series_seq = "" if self.voucher_type == 'Journal Entry': series_seq = 'JEJV' elif self.voucher_type == 'Bank Entry': if self.naming_series == 'Bank Payment Voucher': series_seq = 'JEBP' elif self.naming_series == 'Bank Receipt Voucher': series_seq = 'JEBR' else: series_seq = 'JEBE' elif self.voucher_type == 'Cash Entry': if self.naming_series == 'Cash Payment Voucher': series_seq = 'JECP' elif self.naming_series == 'Cash Receipt Voucher': series_seq = 'JECR' else: series_seq = 'JECA' elif self.voucher_type == 'Debit Note': series_seq = 'JEDN' elif self.voucher_type == 'Credit Note': series_seq = 'JECN' elif self.voucher_type == 'Contra Entry': series_seq = 'JECE' elif self.voucher_type == 'Excise Entry': series_seq = 'JEEE' elif self.voucher_type == 'Write Off Entry': series_seq = 'JEWE' elif self.voucher_type == 'Opening Entry': series_seq = 'JEOP' elif self.voucher_type == 'Depreciation Entry': series_seq = 'JEDE' self.name = make_autoname(str(series_seq) + '.YYYY.MM.#####')
def autoname_sales_order(doc, method): if doc.naming_series == "VPI": m = parser.parse(doc.transaction_date).strftime('%m') if m == "01": add = "A" elif m == "02": add = "B" elif m == "03": add = "C" elif m == "04": add = "D" elif m == "05": add = "E" elif m == "06": add = "F" elif m == "07": add = "G" elif m == "08": add = "H" elif m == "09": add = "I" elif m == "10": add = "J" elif m == "11": add = "K" else: add = "L" doc.name = make_autoname(doc.naming_series + add + '.YY.-.####')
def verifica_check_in(): # loop no Doc a procura de quartos com limite da DATA de ENTRADA. for d in frappe.db.sql("""SELECT codigo,numero_quarto,check_in,check_out,reservation_status, pay_advance FROM `tabRESERVAS` WHERE reservation_status = "Nova" and check_in <=%s """, frappe.utils.now(), as_dict=True): print "RESERVAS +++++++++++++++++++++++++++++++" if (frappe.utils.data.time_diff_in_hours(frappe.utils.now(),d.check_in) >2): reser = frappe.get_doc("RESERVAS",d.codigo) dd= datetime.datetime.fromtimestamp(frappe.utils.data.time_diff_in_hours(frappe.utils.now(),d.check_in)).strftime('%H:%M:%S') # str(frappe.utils.data.time_diff_in_hours(frappe.utils.now(),d.check_in)) ddd = make_autoname('CANCEL/' + '.#####') print " Numer " + ddd frappe.db.sql("INSERT into tabCommunication (name,docstatus,seen,unread_notification_sent,subject,reference_name,reference_doctype,sent_or_received,content,communication_type,creation,modified) values (%s,0,0,0,'RESERVA Cancelada ',%s,'RESERVAS','Sent','RESERVA Cancelada <!-- markdown -->','Comment',%s,%s) ",(ddd,d.codigo,frappe.utils.now(),frappe.utils.now())) # reser._comments =[{"comment": "Reserva " + d.codigo + " " + str(d.check_in) + " Cancelada por mais de " + datetime.datetime.fromtimestamp(dd).strftime('%H:%M:%S') + " horas; by name: " + ddd}] reser._comments = "Reserva " + str(d.codigo) + " " + str(d.check_in) + " Cancelada por mais de " + dd + " horas" print " AGORA " + frappe.utils.now() print " CHECK IN " + str(d.check_in) print "Reserva " + d.codigo + " " + str(d.check_in) + " Cancelada por mais de " + dd + " horas" reser.reservation_status="Cancelada" reser.save() #frappe.redirect_to_message(_('INFORMACAO RESERVAS'),"<div>RESERVA " + d.codigo + " FOI CANCELADA </div>") frappe.publish_realtime(event='msgprint', message='RESERVA ' + d.codigo + ' ' + str(d.check_in) + ' Cancelada por mais de ' + dd + ' horas', user=frappe.session.user,doctype='RESERVAS')
def autoname_folio(self, shareholder, is_company=False): if is_company: doc = self.get_shareholder_doc(shareholder) else: doc = frappe.get_doc('Shareholder' , shareholder) doc.folio_no = make_autoname('FN.#####') doc.save() return doc.folio_no
def autoname(self): supp_master_name = frappe.defaults.get_global_default('supp_master_name') if supp_master_name == 'Supplier Name': if frappe.db.exists("Customer", self.supplier_name): frappe.msgprint(_("A Customer exists with same name"), raise_exception=1) self.name = self.supplier_name else: self.name = make_autoname(self.naming_series + '.#####')
def autoname(self): if frappe.db.get_default("item_naming_by")=="Naming Series" and not self.variant_of: from frappe.model.naming import make_autoname self.item_code = make_autoname(self.naming_series+'.#####') elif not self.item_code: msgprint(_("Item Code is mandatory because Item is not automatically numbered"), raise_exception=1) self.name = self.item_code
def autoname(self): today = datetime.today() #self.name = make_autoname(get_auto_name(self) + "/.#####") monthyear = str(today.year) if len(str(today.month)) < 2: monthyear += "0"+str(today.month) self.name = make_autoname(self.employee+"/LE/"+monthyear+"/.#####")
def make_batch_doc(itm): from frappe.model.naming import make_autoname batch = frappe.new_doc("Batch") batch.batch_id = make_autoname(itm.item_code + ".-" + ".YY.MM.DD" + ".-" + ".#####") batch.item = itm.item_code batch.save(ignore_permissions=True) return batch.batch_id
def autoname(self): cust_master_name = frappe.defaults.get_global_default('cust_master_name') if cust_master_name == 'Customer Name': self.name = self.get_customer_name() else: if not self.naming_series: frappe.throw(_("Series is mandatory"), frappe.MandatoryError) self.name = make_autoname(self.naming_series+'.#####')
def autoname(self): patient_master_name = frappe.defaults.get_global_default('patient_master_name') if patient_master_name == 'Patient Name': self.name = self.get_patient_name() else: if not self.naming_series: frappe.throw(_("Series is mandatory"), frappe.MandatoryError) self.name = make_autoname(self.naming_series+'.#####')
def autoname(self): naming_method = frappe.db.get_value("HR Settings", None, "emp_created_by") if not naming_method: throw(_("Please setup Employee Naming System in Human Resource > HR Settings")) else: if naming_method=='Naming Series': self.name = make_autoname(self.naming_series + '.####') elif naming_method=='Employee Number': self.name = self.employee_number self.employee = self.name
def convert_to_recurring(self): if self.convert_into_recurring_invoice: if not self.recurring_id: frappe.db.set(self, "recurring_id", make_autoname("RECINV/.#####")) self.set_next_date() elif self.recurring_id: frappe.db.sql("""update `tabSales Invoice` set convert_into_recurring_invoice = 0 where recurring_id = %s""", (self.recurring_id,))
def autoname(self): if not self.address_title: if self.links: self.address_title = self.links[0].link_name if self.address_title: self.name = (cstr(self.address_title).strip() + "-" + cstr(_(self.address_type)).strip()) if frappe.db.exists("Address", self.name): self.name = make_autoname(cstr(self.address_title).strip() + "-" + cstr(self.address_type).strip() + "-.#") else: throw(_("Address Title is mandatory."))
def verifica_hora_saida(): print "HORA SAIDA QUARTOS CCCCCCCCCCCCCCCCCCCCCCCC" # loop no Doc a procura de quartos com limite da DATA de ENTRADA. for d in frappe.db.sql("""SELECT name,numero_quarto,hora_entrada,hora_saida,status_reserva FROM `tabGESTAO_QUARTOS` WHERE status_reserva = "Ocupado" and hora_saida <=%s """, frappe.utils.now(), as_dict=True): # print "MINUTOS " + (frappe.utils.data.time_diff_in_seconds(frappe.utils.now(),d.hora_entrada)/60) if (frappe.utils.data.time_diff_in_hours(frappe.utils.now(),d.hora_saida) <= 1): # Avisa que passou do tempo...menos de 1 hora print " Menos de 1 hora" print str(frappe.utils.data.time_diff_in_seconds(frappe.utils.now(),d.hora_entrada)/60) #ASTERISK to call Quarto e mensagem Seu Tempo Terminou max 3 vezes #alert_pbx field get_alertapbx() if alertapbx: #main("Quarto",d.extensao_quarto) print "Ligar para o Quarto avisar" frappe.publish_realtime('msgprint','Este Quarto ja passou da hora. ' + str(frappe.utils.data.time_diff_in_seconds(frappe.utils.now(),d.hora_entrada)/60) + ' minutos a mais.' , user=frappe.session.user) elif (frappe.utils.data.time_diff_in_hours(frappe.utils.now(),d.hora_saida) > 1): frappe.publish_realtime(event='msgprint',message='MENSAGEM QUARTOS') print " MAIS de 1 hora " + d.name reser = frappe.get_doc("GESTAO_QUARTOS",d.name) print reser.numero_quarto # dd= datetime.datetime.fromtimestamp(frappe.utils.data.time_diff_in_seconds(frappe.utils.now(),datetime.datetime(2016, 10, 15, 20, 34, 2))).strftime('%M:%S') dd= datetime.datetime.fromtimestamp(frappe.utils.data.time_diff_in_seconds(frappe.utils.now(),d.hora_entrada)).strftime('%H:%M:%S') # str(frappe.utils.data.time_diff_in_seconds(frappe.utils.now(),d.hora_entrada)) ddd = make_autoname(d.name +'AVISO/' + '.###') frappe.db.sql("INSERT into tabCommunication (name,docstatus,seen,unread_notification_sent,subject,reference_name,reference_doctype,sent_or_received,content,communication_type,creation,modified) values (%s,0,0,0,'HORA DE SAIDA Expirada ',%s,'GESTAO_QUARTOS','Sent','HORA SAIDA Expirada <!-- markdown -->','Comment',%s,%s) ",(ddd,d.name,frappe.utils.now(),frappe.utils.now())) reser._comments = "Hora de Saida por mais de " + dd + " Minutos/Horas" print " AGORA " + frappe.utils.now() print " hora_saida " + str(d.hora_saida) print "QUARTO " + d.numero_quarto + " " + str(d.hora_saida) + " Cancelada por mais de " + dd + " horas" print " USER " + frappe.session.user reser.save() #ASTERISK to call RECEPCAO e mensagem Seu Tempo Terminou max 3 vezes #alert_pbx field get_alertapbx() print "Liga ou nao " + str(alertapbx) if alertapbx: #main("Rececao",numerorececao) print "Ligar para Rececao avisar" frappe.publish_realtime(event='msgprint', message='QUARTO ' + d.numero_quarto + ' ' + str(d.hora_saida) + ' Cancelada por mais de ' + dd + ' Minutos/Minutos', user=frappe.session.user,doctype='GESTAO_QUARTOS')
def convert_to_recurring(doc, autoname, posting_date): if doc.is_recurring: if not doc.recurring_id: frappe.db.set(doc, "recurring_id", make_autoname(autoname)) set_next_date(doc, posting_date) elif doc.recurring_id: frappe.db.sql("""update `tab%s` set is_recurring = 0 where recurring_id = %s""" % (doc.doctype, '%s'), (doc.recurring_id))
def get_name_from_naming_series(self): """ Get a name generated for a Batch from the Batch's naming series. :return: The string that was generated. """ naming_series_prefix = _get_batch_prefix() # validate_template(naming_series_prefix) naming_series_prefix = render_template(str(naming_series_prefix), self.__dict__) key = _make_naming_series_key(naming_series_prefix) name = make_autoname(key) return name
def autoname(self): if not self.address_title: self.address_title = self.customer \ or self.supplier or self.sales_partner or self.lead if self.address_title: self.name = (cstr(self.address_title).strip() + "-" + cstr(self.address_type).strip()) if frappe.db.exists("Address", self.name): self.name = make_autoname(cstr(self.address_title).strip() + "-" + cstr(self.address_type).strip() + "-.#") else: throw(_("Address Title is mandatory."))
def test_serialize_status(self): from frappe.model.naming import make_autoname serial_no = frappe.get_doc({ "doctype": "Serial No", "item_code": "_Test Serialized Item With Series", "serial_no": make_autoname("SR", "Serial No") }) serial_no.save() dn = create_delivery_note(item_code="_Test Serialized Item With Series", serial_no=serial_no.name, do_not_submit=True) self.assertRaises(SerialNoWarehouseError, dn.submit)
def autoname(self): naming_method = frappe.db.get_value("Education Settings", None, "instructor_created_by") if not naming_method: frappe.throw(_("Please setup Instructor Naming System in Education > Education Settings")) else: if naming_method == 'Naming Series': self.name = make_autoname(self.naming_series + '.####') elif naming_method == 'Employee Number': if not self.employee: frappe.throw("Please select Employee") self.name = self.employee elif naming_method == 'Full Name': self.name = self.instructor_name
def autoname(self): cust_master_name = frappe.defaults.get_global_default('cust_master_name') frappe.errprint(cust_master_name) if cust_master_name == 'Customer Name': frappe.errprint("in if...") self.name = self.customer_name frappe.errprint(self.name) else: frappe.errprint("in else...") if not self.naming_series: frappe.throw(_("Series is mandatory"), frappe.MandatoryError) self.name = make_autoname(self.naming_series+'.#####')
def autoname(self): if frappe.db.get_default("item_naming_by")=="Naming Series": if self.variant_of: if not self.item_code: template_item_name = frappe.db.get_value("Item", self.variant_of, "item_name") self.item_code = make_variant_item_code(self.variant_of, template_item_name, self) else: from frappe.model.naming import make_autoname self.item_code = make_autoname(self.naming_series+'.#####', doc=self) elif not self.item_code: msgprint(_("Item Code is mandatory because Item is not automatically numbered"), raise_exception=1) self.item_code = strip(self.item_code) self.name = self.item_code
def test_serialize_status(self): serial_no = frappe.get_doc({ "doctype": "Serial No", "item_code": "_Test Serialized Item With Series", "serial_no": make_autoname("SR", "Serial No") }) serial_no.save() si = frappe.copy_doc(test_records[0]) si.update_stock = 1 si.get("items")[0].item_code = "_Test Serialized Item With Series" si.get("items")[0].qty = 1 si.get("items")[0].serial_no = serial_no.name si.insert() self.assertRaises(SerialNoWarehouseError, si.submit)
def autoname(self): frappe.errprint("name") naming_method = frappe.db.get_value("HR Settings", None, "emp_created_by") if naming_method == "Naming Series": name = make_autoname(self.naming_series + ".####") self.name = name + "-" + self.company elif naming_method == "Employee Number": self.name = self.employee_number # naming_method = frappe.db.get_value("HR Settings", None, "emp_created_by") # if not naming_method: # throw(_("Please setup Employee Naming System in Human Resource > HR Settings")) # else: # if naming_method=='Naming Series': # self.name = make_autoname(self.naming_series + '.####') # elif naming_method=='Employee Number': # self.name = self.employee_number self.employee = self.name
def test_naming_series(self): data = ["TEST-", "TEST/17-18/.test_data./.####", "TEST.YYYY.MM.####"] for series in data: name = make_autoname(series) prefix = series if ".#" in series: prefix = series.rsplit('.',1)[0] prefix = parse_naming_series(prefix) old_current = frappe.db.get_value('Series', prefix, "current", order_by="name") revert_series_if_last(series, name) new_current = cint(frappe.db.get_value('Series', prefix, "current", order_by="name")) self.assertEqual(cint(old_current) - 1, new_current)
def batch_autoname(self): from frappe.model.naming import make_autoname batch_series, batch_wise_cost = frappe.db.get_value("Stock Settings", None, ['batch_series', 'exact_cost_valuation_for_batch_wise_items']) series = 'BTH-.YY.MM.DD.-.###' if batch_wise_cost and batch_series: series = batch_series name = None while not name: name = make_autoname(series, "Batch", self) if frappe.db.exists('Batch', name): name = None self.batch_id = name self.name = name
def autoname(self): """Generate random ID for batch if not specified""" if not self.batch_id: create_new_batch, batch_number_series = frappe.db.get_value('Item', self.item, ['create_new_batch', 'batch_number_series']) if create_new_batch: if batch_number_series: self.batch_id = make_autoname(batch_number_series) elif batch_uses_naming_series(): self.batch_id = self.get_name_from_naming_series() else: self.batch_id = get_name_from_hash() else: frappe.throw(_('Batch ID is mandatory'), frappe.MandatoryError) self.name = self.batch_id
def autoname(self): """Generate random ID for batch if not specified""" if not self.batch_id: create_new_batch, batch_number_series = frappe.db.get_value( 'Item', self.item, ['create_new_batch', 'batch_number_series']) if create_new_batch: if batch_number_series: self.batch_id = make_autoname(batch_number_series) elif batch_uses_naming_series(): self.batch_id = self.get_name_from_naming_series() else: self.batch_id = get_name_from_hash() else: frappe.throw(_('Batch ID is mandatory'), frappe.MandatoryError) self.name = self.batch_id
def autoname(self): if frappe.db.get_default("item_naming_by") == "Naming Series": if self.variant_of: if not self.item_code: self.item_code = make_variant_item_code( self.variant_of, self) else: from frappe.model.naming import make_autoname self.item_code = make_autoname(self.naming_series + '.#####') elif not self.item_code: msgprint(_( "Item Code is mandatory because Item is not automatically numbered" ), raise_exception=1) self.item_code = strip(self.item_code) self.name = self.item_code
def autoname(self): abbr = frappe.db.get_value("Real Estate Property", self.property_group, "abbr") if not abbr: frappe.throw( _(f"Please set the abbreviation of the Real Estate Property {self.property_group}" )) property_no = frappe.db.get_value("Property", self.property, "property_no") if not property_no: frappe.throw( _(f"Please set the property no of the Property {self.property}" )) self.name = make_autoname("-".join([abbr, property_no, ".###"]), "", self)
def generate_serial_no(doc, item_code, qty): serial_no = '' temp_qty = qty while cint(qty) > 0: sn = frappe.new_doc('Serial No') sn.name = make_autoname(str(doc.name) + '/.###') sn.serial_no = sn.name sn.process_status = 'Open' sn.item_code = item_code sn.status = 'Available' sn.save(ignore_permissions=True) if cint(temp_qty) == qty: serial_no = sn.name else: serial_no += '\n' + sn.name qty = cint(qty) - 1 return serial_no
def autoname(self): if frappe.db.get_default("item_naming_by")=="Naming Series": if self.variant_of: if not self.item_code: item_code_suffix = "" for attribute in self.attributes: attribute_abbr = frappe.db.get_value("Item Attribute Value", {"parent": attribute.attribute, "attribute_value": attribute.attribute_value}, "abbr") item_code_suffix += "-" + str(attribute_abbr or attribute.attribute_value) self.item_code = str(self.variant_of) + item_code_suffix else: from frappe.model.naming import make_autoname self.item_code = make_autoname(self.naming_series+'.#####') elif not self.item_code: msgprint(_("Item Code is mandatory because Item is not automatically numbered"), raise_exception=1) self.name = self.item_code
def get_next_value(self): """Will return the next safe value for this serie""" self.split_serie() # make some common validations self.validate_values() self.validate_due_date() from frappe import db db.sql( """ Update tabSeries Set current = {current_value} Where name = %(serie)s """.format(current_value=self.current_value), { "serie": self.get("serie_splited"), }) frappe.db.set(self, "current_value", self.current_value + 1) # reload from the database with all the changes self.reload() # let's make sure that user has not reached the limit self.validate_current_values() # to prevent the system from fetching a # non-updated value db.sql("commit") from frappe.model.naming import make_autoname # if we don't commit before getting here # it will fetch the value from another transaction return make_autoname(self.serie)
def autoname(self): frappe.errprint("name") naming_method = frappe.db.get_value("HR Settings", None, "emp_created_by") if naming_method == 'Naming Series': name = make_autoname(self.naming_series + '.####') self.name = name + '-' + self.company elif naming_method == 'Employee Number': self.name = self.employee_number # naming_method = frappe.db.get_value("HR Settings", None, "emp_created_by") # if not naming_method: # throw(_("Please setup Employee Naming System in Human Resource > HR Settings")) # else: # if naming_method=='Naming Series': # self.name = make_autoname(self.naming_series + '.####') # elif naming_method=='Employee Number': # self.name = self.employee_number self.employee = self.name
def autoname(self): if frappe.db.get_default("item_naming_by")=="Naming Series": if self.variant_of: if not self.item_code: item_code_suffix = "" for attribute in self.attributes: attribute_abbr = frappe.db.get_value("Item Attribute Value", {"parent": attribute.attribute, "attribute_value": attribute.attribute_value}, "abbr") item_code_suffix += "-" + str(attribute_abbr or attribute.attribute_value) self.item_code = str(self.variant_of) + item_code_suffix else: from frappe.model.naming import make_autoname self.item_code = make_autoname(self.naming_series+'.#####') elif not self.item_code: msgprint(_("Item Code is mandatory because Item is not automatically numbered"), raise_exception=1) self.item_code = strip(self.item_code) self.name = self.item_code
def update_serial_nos(sle, item_det): if sle.is_cancelled == "No" and not sle.serial_no and sle.actual_qty > 0 and item_det.serial_no_series: from frappe.model.naming import make_autoname serial_nos = [] for i in xrange(cint(sle.actual_qty)): serial_nos.append(make_autoname(item_det.serial_no_series)) frappe.db.set(sle, "serial_no", "\n".join(serial_nos)) if sle.serial_no: serial_nos = get_serial_nos(sle.serial_no) for serial_no in serial_nos: if frappe.db.exists("Serial No", serial_no): sr = frappe.get_doc("Serial No", serial_no) sr.via_stock_ledger = True sr.warehouse = sle.warehouse if sle.actual_qty > 0 else None sr.save(ignore_permissions=True) elif sle.actual_qty > 0: make_serial_no(serial_no, sle)
def set_jasper_email_doctype(parent_name, sent_to, sender, when, filepath, filename): from frappe.model.naming import make_autoname jer_doc = frappe.new_doc('Jasper Email Report') jer_doc.jasper_email_report_name = parent_name jer_doc.name = make_autoname(parent_name + '/.DD./.MM./.YY./.#######') jer_doc.jasper_email_sent_to = sent_to jer_doc.jasper_email_sender = sender jer_doc.jasper_email_date = when jer_doc.jasper_file_name = filename jer_doc.jasper_report_path = filepath jer_doc.idx = frappe.utils.cint(frappe.db.sql("""select max(idx) from `tabJasper Email Report`""")[0][0]) + 1 jer_doc.ignore_permissions = True jer_doc.insert() return jer_doc
def test_serialize_status(self): from frappe.model.naming import make_autoname serial_no = frappe.get_doc({ "doctype": "Serial No", "item_code": "_Test Serialized Item With Series", "serial_no": make_autoname("SR", "Serial No") }) serial_no.save() dn = create_delivery_note( item_code="_Test Serialized Item With Series", serial_no=serial_no.name, do_not_submit=True) self.assertRaises(SerialNoWarehouseError, dn.submit)
def get_item_tax_template(item_tax_templates, item_tax_map, item_code, parent=None): # search for previously created item tax template by comparing tax maps for template, item_tax_template_map in iteritems(item_tax_templates): if item_tax_map == item_tax_template_map: return template # if no item tax template found, create one item_tax_template = frappe.new_doc("Item Tax Template") item_tax_template.title = make_autoname("Item Tax Template-.####") for tax_type, tax_rate in iteritems(item_tax_map): if not frappe.db.exists("Account", tax_type): parts = tax_type.strip().split(" - ") account_name = " - ".join(parts[:-1]) company = frappe.db.get_value("Company", filters={"abbr": parts[-1]}) parent_account = frappe.db.get_value("Account", filters={ "account_type": "Tax", "root_type": "Liability", "is_group": 0, "company": company }, fieldname="parent_account") frappe.get_doc({ "doctype": "Account", "account_name": account_name, "company": company, "account_type": "Tax", "parent_account": parent_account }).insert() item_tax_template.append("taxes", { "tax_type": tax_type, "tax_rate": tax_rate }) item_tax_templates.setdefault(item_tax_template.title, {}) item_tax_templates[item_tax_template.title][tax_type] = tax_rate item_tax_template.save() return item_tax_template.name
def send_huawei_notification_to_topic(topic, title, body, data=None, custom_android_configuration=None): if not data: data = frappe._dict({}) data.message_id = "HUAWEI-{}-{}".format( topic, make_autoname("hash", "Communication")) # Message id response response = send_huawei_notifications( topic=topic, title=title, body=body, data=data, custom_android_configuration=custom_android_configuration) if response: make_communication_doc(data.message_id, title, body, data, topic=topic)
def verifica_check_in(): # loop no Doc a procura de quartos com limite da DATA de ENTRADA. for d in frappe.db.sql( """SELECT codigo,numero_quarto,check_in,check_out,reservation_status, pay_advance FROM `tabRESERVAS` WHERE reservation_status = "Nova" and check_in <=%s """, frappe.utils.now(), as_dict=True): print "RESERVAS +++++++++++++++++++++++++++++++" if (frappe.utils.data.time_diff_in_hours(frappe.utils.now(), d.check_in) > 2): reser = frappe.get_doc("RESERVAS", d.codigo) dd = datetime.datetime.fromtimestamp( frappe.utils.data.time_diff_in_hours( frappe.utils.now(), d.check_in)).strftime('%H:%M:%S') # str(frappe.utils.data.time_diff_in_hours(frappe.utils.now(),d.check_in)) ddd = make_autoname('CANCEL/' + '.#####') print " Numer " + ddd frappe.db.sql( "INSERT into tabCommunication (name,docstatus,seen,unread_notification_sent,subject,reference_name,reference_doctype,sent_or_received,content,communication_type,creation,modified) values (%s,0,0,0,'RESERVA Cancelada ',%s,'RESERVAS','Sent','RESERVA Cancelada <!-- markdown -->','Comment',%s,%s) ", (ddd, d.codigo, frappe.utils.now(), frappe.utils.now())) # reser._comments =[{"comment": "Reserva " + d.codigo + " " + str(d.check_in) + " Cancelada por mais de " + datetime.datetime.fromtimestamp(dd).strftime('%H:%M:%S') + " horas; by name: " + ddd}] reser._comments = "Reserva " + str(d.codigo) + " " + str( d.check_in) + " Cancelada por mais de " + dd + " horas" print " AGORA " + frappe.utils.now() print " CHECK IN " + str(d.check_in) print "Reserva " + d.codigo + " " + str( d.check_in) + " Cancelada por mais de " + dd + " horas" reser.reservation_status = "Cancelada" reser.save() #frappe.redirect_to_message(_('INFORMACAO RESERVAS'),"<div>RESERVA " + d.codigo + " FOI CANCELADA </div>") frappe.publish_realtime(event='msgprint', message='RESERVA ' + d.codigo + ' ' + str(d.check_in) + ' Cancelada por mais de ' + dd + ' horas', user=frappe.session.user, doctype='RESERVAS')
def item_autoname(self, method): if frappe.db.get_default("item_naming_by") == "Naming Series": if self.variant_of: if not self.item_code: template_item_name = frappe.db.get_value( "Item", self.variant_of, "item_name") self.item_code = make_variant_item_code( self.variant_of, template_item_name, self) else: from frappe.model.naming import make_autoname self.item_code = make_autoname(self.naming_series + '.#####') elif not self.item_code: msgprint(_( "Item Code is mandatory because Item is not automatically numbered" ), raise_exception=1) self.item_code = self.item_code.strip().upper() self.item_name = self.item_code self.name = self.item_code
def autoname(self, method): # concat first and last name _name = " ".join( filter(None, [ cstr(self.get(f)).strip().upper() for f in ["first_name", "last_name"] ])) #self.name = cstr(self.first_name).strip() + cstr(self.last_name).strip() #frappe.throw(_("{0}").format(_name)) if self.phone: _name = _name + ' - ' + cstr(self.phone).strip() elif self.mobile_no: _name = _name + " - " + cstr(self.mobile_no).strip() if frappe.db.exists("Contact", _name): self.name = make_autoname(_name + '/.##') else: self.name = _name
def autoname(self): naming_method = frappe.db.get_value("HR Settings", None, "emp_created_by") if not naming_method: throw( _("Please setup Employee Naming System in Human Resource > HR Settings" )) else: if naming_method == 'Naming Series': self.name = make_autoname(self.naming_series + '.####') elif naming_method == 'Employee Number': # if naming_method == 'Naming Series': # self.name = make_autoname(self.naming_series + '.####') # elif naming_method == 'Employee Number': self.name = self.employee_number self.employee = self.name
def autoname(self): self.ficha_numero = make_autoname(self.naming_series) self.name = self.ficha_numero if self.entrada_ou_saida_viatura == "Entrada": print('autoname entrada') self.docstatus = 0 else: frappe.db.set_value("Vehicle", self.matricula_veiculo, "entrada_ou_saida", "Stand-by") frappe.db.commit() print('primeiro registo...') print('primeiro registo...') print('primeiro registo...') print('primeiro registo...') self.docstatus = 0
def send_huawei_notification_to_user(user, title, body, data=None, custom_android_configuration=None): tokens = get_huawei_tokens_for("Users", users=[user]) if not data: data = frappe._dict({}) # for saving purpose data.message_id = "HUAWEI-{}-{}".format( user, make_autoname("hash", "Communication")) # Batch Response response = send_huawei_notifications( tokens=tokens, title=title, body=body, data=data, custom_android_configuration=custom_android_configuration) if response: make_communication_doc(data.message_id, title, body, data, user=user)
def caixa_movimentos_in(start,caixa,fecho): total_tpa = 0 total_ccorrente = 0 total_caixa = 0 for d in frappe.db.sql("""select hora_atendimento, name,total_servicos,pagamento_por, status_atendimento, bar_tender from `tabBAR_RESTAURANTE` where status_atendimento ='Fechado' and hora_atendimento >= %(start)s and hora_atendimento <= %(end)s """, {"start": start,"end": frappe.utils.now() }, as_dict=True): #for d in frappe.db.sql("""SELECT codigo,numero_quarto,check_in,check_out,reservation_status, pay_advance FROM `tabRESERVAS` WHERE reservation_status = "Nova" and check_in <=%s """, frappe.utils.now(), as_dict=True): print "MOVIMENTOS BAR RESTAURANTE +++++++++++++++++++++++++++++++" ddd = make_autoname('MOV-' + '.#####') if len(frappe.db.sql("SELECT name,descricao_movimento from tabMovimentos_Caixa WHERE descricao_movimento=%(mov)s""",{"mov":d.name}, as_dict=True))==0: frappe.db.sql("INSERT into tabMovimentos_Caixa (name, docstatus, parent, parenttype, parentfield, tipo_pagamento, descricao_movimento, valor_pago, hora_atendimento, creation, modified, usuario_movimentos) values (%s,0,%s,'CAIXA_Registadora','movimentos_caixa',%s,%s,%s,%s,%s,%s,%s) ",(ddd, caixa, d.pagamento_por ,d.name, d.total_servicos, d.hora_atendimento, frappe.utils.now(), frappe.utils.now(),d.bar_tender)) total_caixa = d.total_servicos+total_caixa if (d.pagamento_por == "TPA"): total_tpa = d.total_servicos+total_tpa if (d.pagamento_por == "Conta-Corrente"): total_ccorrente = d.total_servicos+total_ccorrente print "Abre Caixa" print total_caixa reser = frappe.get_doc("CAIXA_Registadora",caixa) if (total_caixa > 1) and (reser.amount_caixa == 0): reser.amount_caixa = total_caixa+reser.amount_caixa reser.amount_tpa = total_tpa+reser.amount_tpa reser.amount_conta_corrente = total_ccorrente+reser.amount_conta_corrente reser.status_caixa='Em Curso' reser.save() elif (total_caixa > 1) and (reser.amount_caixa >= 0): reser.amount_caixa = total_caixa+reser.amount_caixa reser.amount_tpa = total_tpa+reser.amount_tpa reser.amount_conta_corrente = total_ccorrente+reser.amount_conta_corrente reser.save() print fecho print reser.status_caixa if (fecho==2): reser.status_caixa='Fechado' reser.save() return total_caixa
def preview_series(self) -> str: """Preview what the naming series will generate.""" generated_names = [] series = self.naming_series_to_check if not series: return "" try: doc = self._fetch_last_doc_if_available() for _count in range(3): generated_names.append(make_autoname(series, doc=doc)) except Exception as e: if frappe.message_log: frappe.message_log.pop() return _( "Failed to generate names from the series") + f"\n{str(e)}" # Explcitly rollback in case any changes were made to series table. frappe.db.rollback() # nosemgrep return "\n".join(generated_names)
def set_jasper_email_doctype(parent_name, sent_to, sender, when, filepath, filename): from frappe.model.naming import make_autoname jer_doc = frappe.new_doc('Jasper Email Report') jer_doc.jasper_email_report_name = parent_name jer_doc.name = make_autoname(parent_name + '/.DD./.MM./.YY./.#######') jer_doc.jasper_email_sent_to = sent_to jer_doc.jasper_email_sender = sender jer_doc.jasper_email_date = when jer_doc.jasper_file_name = filename jer_doc.jasper_report_path = filepath jer_doc.idx = frappe.utils.cint( frappe.db.sql("""select max(idx) from `tabJasper Email Report`""")[0] [0]) + 1 jer_doc.ignore_permissions = True jer_doc.insert() return jer_doc
def get_item_tax_template(item_tax_templates, item_tax_map, item_code, parenttype=None, parent=None): # search for previously created item tax template by comparing tax maps for template, item_tax_template_map in iteritems(item_tax_templates): if item_tax_map == item_tax_template_map: return template # if no item tax template found, create one item_tax_template = frappe.new_doc("Item Tax Template") item_tax_template.title = make_autoname("Item Tax Template-.####") for tax_type, tax_rate in iteritems(item_tax_map): account_details = frappe.db.get_value("Account", tax_type, ['name', 'account_type'], as_dict=1) if account_details: if account_details.account_type not in ('Tax', 'Chargeable', 'Income Account', 'Expense Account', 'Expenses Included In Valuation'): frappe.db.set_value('Account', account_details.name, 'account_type', 'Chargeable') else: parts = tax_type.strip().split(" - ") account_name = " - ".join(parts[:-1]) company = get_company(parts[-1], parenttype, parent) parent_account = frappe.db.get_value("Account", filters={"account_type": "Tax", "root_type": "Liability", "is_group": 0, "company": company}, fieldname="parent_account") filters = { "account_name": account_name, "company": company, "account_type": "Tax", "parent_account": parent_account } tax_type = frappe.db.get_value("Account", filters) if not tax_type: account = frappe.new_doc("Account") account.update(filters) account.insert() tax_type = account.name item_tax_template.append("taxes", {"tax_type": tax_type, "tax_rate": tax_rate}) item_tax_templates.setdefault(item_tax_template.title, {}) item_tax_templates[item_tax_template.title][tax_type] = tax_rate item_tax_template.save() return item_tax_template.name
def employee_autoname(doc, method): # frappe.errprint("Inside autoname emp ") total = 0 company_code = str( frappe.db.get_value("Company", {"name": doc.company}, "code")) employmement_code = doc.code number = make_autoname(company_code + str(employmement_code) + '.####') # temp_code=number.split() for i in number: j = 1 if j % 2 == 0: total = total + int(i) * 1 j += 1 else: total = total + int(i) * 3 j += 1 sum_last_digit = total % 10 if sum_last_digit == 0: check_digit = 0 else: check_digit = 10 - sum_last_digit doc.name = str(number) + str(check_digit)
def _rename_doc(doctype, name, naming_series): if frappe.get_meta(doctype).get_field("amended_from"): amended_from = frappe.db.get_value(doctype, name, "amended_from") else: amended_from = None if amended_from: am_id = 1 am_prefix = amended_from if frappe.db.get_value(doctype, amended_from, "amended_from"): am_id = cint(amended_from.split('-')[-1]) + 1 am_prefix = '-'.join( amended_from.split('-')[:-1]) # except the last hyphen fixed_name = am_prefix + '-' + str(am_id) else: fixed_name = make_autoname(naming_series + '.#####') frappe.db.set_value(doctype, name, "naming_series", naming_series) frappe.rename_doc(doctype, name, fixed_name, force=True) add_comment(doctype, name, fixed_name) return fixed_name
def autoname(self): if frappe.form_dict.client == "app" and not self.goods_receipt_number: self.name = make_autoname('GR-16-.#')
def generate_patient_id(doc, method): if (frappe.db.get_value("OP Settings", None, "patient_id")=='1'): pid = make_autoname(frappe.db.get_value("OP Settings", None, "id_series"), "", doc) doc.patient_id = pid doc.save() send_registration_sms(doc, method)
def autoname(self): self.name = make_autoname(self.series)
def autoname(self): self.name = make_autoname(self.customer + "/" + self.checks_group + "/" + today() + "/.###")