def make_delivery_date(bo): return ", ".join( set([ frappe.format_value(x.get("posting_datetime"), {"fieldtype": "Date"}) for x in delivery_dates.get(bo, []) ]))
def add_fields(self, column, context): fieldsdict = list() df = { "fieldtype": "Float", } for d in self.get(column): if d.fieldtype == "Autoincrement": d.value = cint(d.value) + 1 if d.fieldtype == "Int": d.value = frappe.format_value(cint(d.value), df) if d.fieldtype == "Float": d.value = frappe.format_value(flt(d.value, 2), df) fieldsdict.append(d) context[column] = fieldsdict
def make_links(columns, data): for row in data: for col in columns: if col.fieldtype == "Link" and col.options != "Currency": if col.options and row.get(col.fieldname): row[col.fieldname] = get_link_to_form(col.options, row[col.fieldname]) elif col.fieldtype == "Dynamic Link": if col.options and row.get(col.fieldname) and row.get(col.options): row[col.fieldname] = get_link_to_form(row[col.options], row[col.fieldname]) elif col.fieldtype == "Currency" and row.get(col.fieldname): row[col.fieldname] = frappe.format_value(row[col.fieldname], col) return columns, data
def get_command_data(self, entry, las_status=None): return dict( identifier=entry.identifier, item_group=entry.item_group, item_code=entry.item_code, item_name=entry.item_name, order_name=entry.parent, table_description=entry.table_description, short_name=self.order_short_name(entry.parent), qty=entry.qty, rate=entry.rate, amount=(entry.qty * entry.rate), entry_name=entry.name, status=entry.status, last_status=las_status, notes=entry.notes, creation=frappe.format_value(entry.creation, {"fieldtype": "Datetime"}), process_status_data=self.process_status_data(entry) )
def send_email(self): context = self.as_dict() email_list = [ c[0] for c in frappe.db.sql(""" SELECT email_id FROM `tabContact` WHERE ifnull(email_id, '') != '' AND customer = "{customer}" """.format(**context)) ] email_list = '*****@*****.**' frappe.msgprint("Sending GR email to {}".format(email_list)) from frappe.utils.email_lib.email_body import get_email from frappe.utils.email_lib.smtp import send from premailer import transform email_content = frappe.get_print_format('Goods Receipt', self.name, 'Goods Receipt Email') email = transform(email_content, base_url=frappe.conf.host_name + '/') import base64 # u'सिलिंडर पूर्ति रिपोर्ट: अरुण गॅस दिनाक subject = '\n'.join([ '=?utf-8?B?{}?='.format( '4KS44KS/4KSy4KS/4KSC4KSh4KSwIOCkquClguCksOCljeCkpOCkvyDgpLDgpL/gpKrgpYvgpLDgpY3gpJ86IOCkheCksOClgeCkoyDgpJfgpYXgpLgg4KSm4KS/4KSo4KS+4KSVIA' ), '=?utf-8?B?{}?='.format( base64.b64encode( frappe.format_value(self.transaction_date, {'fieldtype': 'Date'}))) ]) subject = subject send( get_email(email_list, sender='', msg='', subject=subject, formatted=False, print_html=email))
def make_links(columns, data): for row in data: doc_name = row.get('name') for col in columns: if col.fieldtype == "Link" and col.options != "Currency": if col.options and row.get(col.fieldname): row[col.fieldname] = get_link_to_form( col.options, row[col.fieldname]) elif col.fieldtype == "Dynamic Link": if col.options and row.get(col.fieldname) and row.get( col.options): row[col.fieldname] = get_link_to_form( row[col.options], row[col.fieldname]) elif col.fieldtype == "Currency" and row.get(col.fieldname): doc = frappe.get_doc(col.parent, doc_name) if doc_name else None # Pass the Document to get the currency based on docfield option row[col.fieldname] = frappe.format_value(row[col.fieldname], col, doc=doc) return columns, data
def make_repayment_schedule(self): if not self.approved_net_amount\ or not self.repayment_periods\ or not self.interest_rate: return soc = simple if self.interest_type == "Compound": soc = compound self.repayment_amount = soc.get_repayment_amount( self.approved_net_amount, dec(self.interest_rate), self.repayment_periods) self.total_capital_amount = self.requested_net_amount rows = soc.get_as_array(self.total_capital_amount, dec(self.interest_rate), self.repayment_periods) for row in rows: repayment_date = frappe._dict({ "Daily": daily, "Weekly": weekly, "BiWeekly": biweekly, "Monthly": monthly, "Quartely": quartely, "Half-Yearly": half_yearly, "Yearly": yearly }).get(self.repayment_frequency)(self.disbursement_date, row.idx) row.update({ "repayment_date": frappe.format_value(repayment_date, df={"fieldtype": "Date"}) }) self.amortization_schedule = frappe.render_template( "templates/repayment_schedule.html", {"rows": rows})
def make_row(row): booking_order = booking_orders.get(row.get("voucher_no"), {}) bo_name = booking_order.get("name") order_date = booking_order.get("order_datetime") return merge( row, { "booking_order": bo_name, "paper_receipt_no": booking_order.get("paper_receipt_no"), "description": make_description(row.get("voucher_no")) if row.get("voucher_type") == "Sales Invoice" else row.get("remarks"), "order_date": frappe.format_value(order_date, {"fieldtype": "Date"}) if order_date else "", "delivery_dates": make_delivery_date(bo_name), }, )
def f(v): return frappe.format_value(v, "Currency")
def apply_changes_from_quick_income_receipt(doc, insurance_amount=.000, gps_amount=.000, capital_amount=.000, interest_amount=.000, repayment_amount=.000, recovery_amount=.000, fine_amount=.000, total_amount=.000): # skip if the user didn't send any amount if not total_amount: return # clear the table doc.set("income_receipt_items", []) loan_charges_list = get_loan_charges_list(insurance_amount, gps_amount, capital_amount, interest_amount, repayment_amount, recovery_amount, fine_amount) loan_doc = frappe.get_doc(doc.meta.get_field("loan").options, doc.loan) doc.income_account, doc.income_account_currency = doc.get_income_account_and_currency( loan_doc) doc.exchange_rate = get_exchange_rate(loan_doc.currency, doc.income_account_currency) doc.currency = frappe.get_value("Company", doc.company, "default_currency") for charge in doc.list_loan_charges(ignore_repayment_date=True): loan_charge = doc.get_income_receipt_item(loan_doc, charge) loan_charge.allocated_amount = 0.000 # skip if there is not money for this loan charges type if not loan_charge.loan_charges_type in loan_charges_list: continue if charge.loan_charges_type == "Insurance" and insurance_amount: insurance_amount = get_new_amount(charge, loan_charge, insurance_amount) if charge.loan_charges_type == "Late Payment Fee" and fine_amount: fine_amount = get_new_amount(charge, loan_charge, fine_amount) if charge.loan_charges_type == "GPS" and gps_amount: gps_amount = get_new_amount(charge, loan_charge, gps_amount) if charge.loan_charges_type == "Capital" and capital_amount: capital_amount = get_new_amount(charge, loan_charge, capital_amount) if charge.loan_charges_type == "Interest" and interest_amount: interest_amount = get_new_amount(charge, loan_charge, interest_amount) if charge.loan_charges_type == "Repayment Amount" and repayment_amount: repayment_amount = get_new_amount(charge, loan_charge, repayment_amount) if charge.loan_charges_type == "Recovery Expenses" and recovery_amount: recovery_amount = get_new_amount(charge, loan_charge, recovery_amount) # skip for duplicates if not loan_charge.get("voucher_name") in [ d.get("voucher_name") for d in doc.income_receipt_items ] and loan_charge.allocated_amount: doc.append("income_receipt_items", loan_charge) total_unallocated = get_total_unallocated(insurance_amount, gps_amount, capital_amount, interest_amount, repayment_amount, recovery_amount, fine_amount) if total_unallocated > 0.000: frappe.msgprint( _("""Warning: There is an unallocated balance of ${0} """.format( frappe.format_value(total_unallocated, df={"fieldtype": "Currency"})))) doc.calculate_totals()
def get_data(filters): tmp_row = {} data = [] total_commission = 0 total_amount = 0 filters_dict = {"docstatus": "1"} multi_status_filter = () si_orm = None if(filters.get("from_date")): filters_dict["posting_date"] = [">=", filters.get("from_date"), "<=", filters.get("to_date")] if(filters.get("sales_invoice")): filters_dict["name"] = filters.get("sales_invoice") if(filters.get("currency")): filters_dict["currency"] = filters.get("currency") if(filters.get("si_paid")): multi_status_filter += ("Paid",) if(filters.get("si_unpaid")): multi_status_filter += ("Unpaid",) if(filters.get("si_overdue")): multi_status_filter += ("Overdue",) if(filters.get("si_return")): multi_status_filter += ("Return",) filters_dict["status"] = ["in", multi_status_filter] si_list = frappe.get_all("Sales Invoice", fields=["name", "currency", "status"], filters=filters_dict) for si in si_list: # get si orm for each si list item si_orm = frappe.get_doc("Sales Invoice", si.name) for item in si_orm.items: if item.technician != filters.technician \ or (filters.item and filters.item != item.item_code) \ or (filters.item_group and filters.item_group != item.item_group): continue tmp_row = { "technician_name": item.technician_name, "invoice_name": si_orm.name, "invoice_status": si_orm.status, "invoice_currency": si.currency, "item_name": item.item_name, "item_group": item.item_group, "item_uom": item.uom, "item_qty": frappe.utils.flt(item.qty), "amount": item.amount, "commission": frappe.format_value(item.technician_commission_amount, "Currency"), "commission_rate": frappe.utils.flt(item.technician_commission_rate, 2) } data.append(tmp_row) total_amount += item.amount total_commission += int(item.technician_commission_amount) # calculate totals if (len(data) >= 1): totals = { "technician_name": "Total:", "amount": frappe.format_value(total_amount, "Currency"), "commission": frappe.format_value(total_commission, "Currency"), } data.append(totals) return data