def fetch_pausen_von_ts(ts): ts = frappe.get_doc("Timesheet", ts) total_arbeitszeit = 0 total_pausenzeit = 0 start = '' ende = '' pausen = [] #arbeitszeit & pause for log in ts.time_logs: if _(log.activity_type) == _('Arbeitszeit'): start = get_time(log.from_time).strftime("%H:%M:%S") ende = get_time(log.to_time).strftime("%H:%M:%S") total_arbeitszeit += log.hours if _(log.activity_type) == _('Pause'): pause = {} pause["start"] = get_time(log.from_time).strftime("%H:%M:%S") pause["dauer"] = log.hours pause["referenz"] = log.name pausen.append(pause) total_pausenzeit += log.hours total_arbeitszeit -= log.hours #/arbeitszeit & pause return { 'total_arbeitszeit': total_arbeitszeit, 'total_pausenzeit': total_pausenzeit, 'start': start, 'ende': ende, 'pausen': pausen }
def create_purchase_receipt(doc, model): po = frappe.get_doc({ "doctype": "Purchase Order", "name": doc.name, "transaction_date": doc.transaction_date }) pr = make_purchase_receipt(po.name) pr.posting_date = po.transaction_date pr.posting_time = get_time("00:00:00") pr.set_posting_time = 1 pr.save() pr.submit()
def test_get_time(self): datetime_input = now_datetime() timedelta_input = get_timedelta() time_input = nowtime() self.assertIsInstance(get_time(datetime_input), time) self.assertIsInstance(get_time(timedelta_input), time) self.assertIsInstance(get_time(time_input), time) self.assertIsInstance(get_time("100:2:12"), time) self.assertIsInstance(get_time(str(datetime_input)), time) self.assertIsInstance(get_time(str(timedelta_input)), time) self.assertIsInstance(get_time(str(time_input)), time)
def create_qr_code(doc, method=None): region = get_region(doc.company) if region not in ["Saudi Arabia"]: return # if QR Code field not present, create it. Invoices without QR are invalid as per law. if not hasattr(doc, "ksa_einv_qr"): create_custom_fields({ doc.doctype: [ dict( fieldname="ksa_einv_qr", label="KSA E-Invoicing QR", fieldtype="Attach Image", read_only=1, no_copy=1, hidden=1, ) ] }) # Don't create QR Code if it already exists qr_code = doc.get("ksa_einv_qr") if qr_code and frappe.db.exists({"doctype": "File", "file_url": qr_code}): return meta = frappe.get_meta(doc.doctype) if "ksa_einv_qr" in [d.fieldname for d in meta.get_image_fields()]: """TLV conversion for 1. Seller's Name 2. VAT Number 3. Time Stamp 4. Invoice Amount 5. VAT Amount """ tlv_array = [] # Sellers Name seller_name = frappe.db.get_value("Company", doc.company, "company_name_in_arabic") if not seller_name: frappe.throw( _("Arabic name missing for {} in the company document").format( doc.company)) tag = bytes([1]).hex() length = bytes([len(seller_name.encode("utf-8"))]).hex() value = seller_name.encode("utf-8").hex() tlv_array.append("".join([tag, length, value])) # VAT Number tax_id = frappe.db.get_value("Company", doc.company, "tax_id") if not tax_id: frappe.throw( _("Tax ID missing for {} in the company document").format( doc.company)) tag = bytes([2]).hex() length = bytes([len(tax_id)]).hex() value = tax_id.encode("utf-8").hex() tlv_array.append("".join([tag, length, value])) # Time Stamp posting_date = getdate(doc.posting_date) time = get_time(doc.posting_time) seconds = time.hour * 60 * 60 + time.minute * 60 + time.second time_stamp = add_to_date(posting_date, seconds=seconds) time_stamp = time_stamp.strftime("%Y-%m-%dT%H:%M:%SZ") tag = bytes([3]).hex() length = bytes([len(time_stamp)]).hex() value = time_stamp.encode("utf-8").hex() tlv_array.append("".join([tag, length, value])) # Invoice Amount invoice_amount = str(doc.grand_total) tag = bytes([4]).hex() length = bytes([len(invoice_amount)]).hex() value = invoice_amount.encode("utf-8").hex() tlv_array.append("".join([tag, length, value])) # VAT Amount vat_amount = str(get_vat_amount(doc)) tag = bytes([5]).hex() length = bytes([len(vat_amount)]).hex() value = vat_amount.encode("utf-8").hex() tlv_array.append("".join([tag, length, value])) # Joining bytes into one tlv_buff = "".join(tlv_array) # base64 conversion for QR Code base64_string = b64encode(bytes.fromhex(tlv_buff)).decode() qr_image = io.BytesIO() url = qr_create(base64_string, error="L") url.png(qr_image, scale=2, quiet_zone=1) name = frappe.generate_hash(doc.name, 5) # making file filename = f"QRCode-{name}.png".replace(os.path.sep, "__") _file = frappe.get_doc({ "doctype": "File", "file_name": filename, "is_private": 0, "content": qr_image.getvalue(), "attached_to_doctype": doc.get("doctype"), "attached_to_name": doc.get("name"), "attached_to_field": "ksa_einv_qr", }) _file.save() # assigning to document doc.db_set("ksa_einv_qr", _file.file_url) doc.notify_update()
def get_visual_overview(ts): ts = frappe.get_doc("Timesheet", ts) html_to_return = '<div class="row"><div class="col-sm-12"><div id="chart"></div></div>' total_arbeitszeit = 0 total_beratnugszeit = 0 total_mandatszeit = 0 total_diverses = 0 #arbeitszeit html_to_return += '<div class="col-sm-4"><h2>Präsenzzeit</h2>' for log in ts.time_logs: if log.activity_type == 'Arbeitszeit': html_to_return += 'Von: ' + get_time( log.from_time).strftime("%H:%M:%S") + ' bis: ' + get_time( log.to_time).strftime("%H:%M:%S") + ' Total: ' + str( log.hours) + 'h' total_arbeitszeit += log.hours html_to_return += '<h2>Pausen</h2>' for log in ts.time_logs: if log.activity_type == 'Pause': html_to_return += get_time( log.from_time).strftime("%H:%M:%S") + ': ' + str( log.hours) + 'h<br>' total_arbeitszeit -= log.hours html_to_return += '</div>' #/arbeitszeit #Mandate/Anfrage html_to_return += '<div class="col-sm-4"><h2>Beratungen / Mandate</h2>' for log in ts.time_logs: if log.activity_type == 'Beratung': html_to_return += 'Beratung (' + log.spo_referenz + '): ' + str( log.hours) + 'h<br>' total_beratnugszeit += log.hours if log.activity_type == 'Mandatsarbeit': html_to_return += 'Mandatsarbeit (' + log.spo_referenz + '): ' + str( log.hours) + 'h<br>' total_mandatszeit += log.hours html_to_return += '</div>' #/Mandate/Anfrage #diverses html_to_return += '<div class="col-sm-4"><h2>Diverses</h2>' for log in ts.time_logs: if log.activity_type != 'Beratung' and log.activity_type != 'Mandatsarbeit' and log.activity_type != 'Pause' and log.activity_type != 'Arbeitszeit': html_to_return += log.activity_type + ': ' + str( log.hours) + 'h<br>' total_diverses += log.hours html_to_return += '</div>' #/diverses html_to_return += '</div>' return { 'html': html_to_return, 'docstatus': ts.docstatus, 'arbeitszeit': total_arbeitszeit, 'total_beratungszeit': total_beratnugszeit, 'total_mandatszeit': total_mandatszeit, 'total_diverses': total_diverses }