def update_payment_req_status(doc, method): from erpnext.accounts.doctype.payment_entry.payment_entry import get_reference_details for ref in doc.references: payment_request_name = frappe.db.get_value( "Payment Request", { "reference_doctype": ref.reference_doctype, "reference_name": ref.reference_name, "docstatus": 1 }) if payment_request_name: ref_details = get_reference_details(ref.reference_doctype, ref.reference_name, doc.party_account_currency) pay_req_doc = frappe.get_doc('Payment Request', payment_request_name) status = pay_req_doc.status if status != "Paid" and not ref_details.outstanding_amount: status = 'Paid' elif status != "Partially Paid" and ref_details.outstanding_amount != ref_details.total_amount: status = 'Partially Paid' elif ref_details.outstanding_amount == ref_details.total_amount: if pay_req_doc.payment_request_type == 'Outward': status = 'Initiated' elif pay_req_doc.payment_request_type == 'Inward': status = 'Requested' pay_req_doc.db_set('status', status) frappe.db.commit()
def create_journal_entry(self): for d in self.get('items'): pme = frappe.new_doc("Payment Entry") paid_from_account_name = frappe.db.get_value("Bank Detail", self.bank_account, "account") company_name = frappe.db.get_value("Account", paid_from_account_name, "company") posting_date_today = datetime.date.today() party_details = get_party_details(company_name, "Supplier", d.supplier_name, posting_date_today) paid_from_account_detail = get_account_details(paid_from_account_name, posting_date_today) paid_to_account_detail = get_account_details(party_details["party_account"], posting_date_today) reference_detail = get_reference_details("Purchase Invoice", d.purchase_invoice, party_details["party_account_currency"]) json_update = { "naming_series": "PE-", "payment_type": "Pay", "party_type": "Supplier", "party": d.supplier_name, "posting_date": datetime.date.today(), "company" : company_name, "mode_of_payment": "Bank Transfer", "paid_from": paid_from_account_name, "paid_amount":d.grand_total, "paid_from_account_currency": party_details["party_account_currency"], "party_balance": party_details["party_balance"], "paid_to" : party_details["party_account"], "paid_to_account_currency": paid_to_account_detail["account_currency"], "paid_to_account_balance" : paid_to_account_detail["account_balance"], "received_amount" : d.grand_total, "reference_no" : self.file_creation_number, "reference_date" : posting_date_today, "references" : [{ "reference_doctype": "Purchase Invoice", "reference_name": d.purchase_invoice, "due_date": reference_detail["due_date"], "total_amount": reference_detail["total_amount"], "outstanding_amount": reference_detail["outstanding_amount"], "allocated_amount": d.grand_total, "exchange_rate": reference_detail["exchange_rate"] }] } pme.update (json_update) #frappe.msgprint(str(json_update)) pme.save()
def create_payment_entry_list(self, list1, mode_of_payment): for supplier, dict_invoice in self.create_dict_from_list( list1).items(): cheque_series = 0 if mode_of_payment == "Cheque CDN" or mode_of_payment == "Cheque USD": cheque_series = frappe.db.get_value("Cheque Series", self.bank_account, "cheque_series") cheque_series = int(cheque_series) + 1 if mode_of_payment != "Cheque CDN" and mode_of_payment != "Cheque USD": cheque_series = self.file_creation_number pme = frappe.new_doc("Payment Entry") paid_from_account_name = frappe.db.get_value( "Electronic Funds Transfer Bank Detail", self.bank_account, "account") company_name = frappe.db.get_value("Account", paid_from_account_name, "company") posting_date_today = utils.today() posting_date_today = utils.getdate(self.posting_date) party_details = get_party_details(company_name, "Supplier", supplier, posting_date_today) paid_from_account_detail = get_account_details( paid_from_account_name, posting_date_today) paid_to_account_detail = get_account_details( party_details["party_account"], posting_date_today) json_update = { "naming_series": "PE-", "payment_type": "Pay", "party_type": "Supplier", "party": supplier, "posting_date": datetime.date.today(), "company": company_name, "mode_of_payment": mode_of_payment, "paid_from": paid_from_account_name, "paid_from_account_currency": party_details["party_account_currency"], "party_balance": party_details["party_balance"], "paid_to": party_details["party_account"], "paid_to_account_currency": paid_to_account_detail["account_currency"], "paid_to_account_balance": paid_to_account_detail["account_balance"], "reference_no": cheque_series, "reference_date": posting_date_today, } pme.update(json_update) received_amount = 0.00 #frappe.msgprint(str(json_update)) for invoice_name, grand_total in dict_invoice.items(): if grand_total > 0: received_amount = received_amount + grand_total reference_detail = get_reference_details( "Purchase Invoice", invoice_name, party_details["party_account_currency"]) pme.append( "references", { "reference_doctype": "Purchase Invoice", "reference_name": invoice_name, "due_date": reference_detail["due_date"], "total_amount": reference_detail["total_amount"], "outstanding_amount": reference_detail["outstanding_amount"], "allocated_amount": grand_total, "exchange_rate": reference_detail["exchange_rate"] }) else: pi = frappe.get_doc("Purchase Invoice", invoice_name) reference_detail = get_reference_details( "Purchase Invoice", pi.return_against, party_details["party_account_currency"]) if reference_detail["outstanding_amount"] < 0: pmer = frappe.new_doc("Payment Entry") json_update = { "naming_series": "PE-", "payment_type": "Receive", "party_type": "Supplier", "party": supplier, "posting_date": datetime.date.today(), "company": company_name, "mode_of_payment": mode_of_payment, "paid_from": party_details["party_account"], "paid_from_account_currency": paid_to_account_detail["account_currency"], "party_balance": party_details["party_balance"], "paid_to": paid_from_account_name, "paid_to_account_currency": party_details["party_account_currency"], "paid_to_account_balance": paid_to_account_detail["account_balance"], "reference_no": cheque_series, "reference_date": posting_date_today, } pmer.update(json_update) pmer.append( "references", { "reference_doctype": "Purchase Invoice", "reference_name": pi.return_against, "due_date": reference_detail["due_date"], "total_amount": reference_detail["total_amount"], "outstanding_amount": reference_detail["outstanding_amount"], "allocated_amount": grand_total, "exchange_rate": reference_detail["exchange_rate"] }) #frappe.msgprint(str(0-grand_total)) pmer.received_amount = 0 - grand_total pmer.paid_amount = 0 - grand_total pmer.save() pmer.submit() pme.received_amount = received_amount pme.paid_amount = received_amount if received_amount != 0: pme.save() pme.submit() if mode_of_payment == "Cheque CDN" or mode_of_payment == "Cheque USD": frappe.client.set_value("Cheque Series", self.bank_account, "cheque_series", cheque_series) frappe.msgprint("Payment Entry are created.") frappe.db.set(self, 'is_payment_entry_generated', True)