From c9dd543fef73e9ccb4529956c0ab3beac6b1e873 Mon Sep 17 00:00:00 2001 From: Sathisha Poojary Date: Fri, 17 Nov 2017 12:29:31 +0530 Subject: [PATCH] https://github.com/sathishpy/corrugation/issues/13 Some more changes to make transaction mapping easier 1. Find transactions without proper description from invoices, by matching invoice amount 2. Create journal entries for new transaction --- .../cm_payment_manager/cm_payment_manager.js | 10 ++- .../cm_payment_manager.json | 62 +++++++++++++++++-- .../cm_payment_manager/cm_payment_manager.py | 25 ++++++-- 3 files changed, 83 insertions(+), 14 deletions(-) diff --git a/corrugation/corrugation/doctype/cm_payment_manager/cm_payment_manager.js b/corrugation/corrugation/doctype/cm_payment_manager/cm_payment_manager.js index ea60f87..7b23b1c 100644 --- a/corrugation/corrugation/doctype/cm_payment_manager/cm_payment_manager.js +++ b/corrugation/corrugation/doctype/cm_payment_manager/cm_payment_manager.js @@ -46,9 +46,15 @@ frappe.ui.form.on('CM Payment Manager', { frm.set_query("invoice", "payment_invoice_items", function(doc, cdt, cdn) { row = locals[cdt][cdn] if (row.party_type == "Customer") { - return { filters:[[row.invoice_type, "customer", "in", [row.party]]]} + return { + filters:[[row.invoice_type, "customer", "in", [row.party]], + [row.invoice_type, "status", "!=", "Cancelled" ],] + } } else if (row.party_type == "Supplier") { - return { filters:[[row.invoice_type, "supplier", "in", [row.party]]]} + return { + filters:[[row.invoice_type, "supplier", "in", [row.party]], + [row.invoice_type, "status", "!=", "Cancelled" ],] + } } }); }, diff --git a/corrugation/corrugation/doctype/cm_payment_manager/cm_payment_manager.json b/corrugation/corrugation/doctype/cm_payment_manager/cm_payment_manager.json index 9265a05..176524e 100644 --- a/corrugation/corrugation/doctype/cm_payment_manager/cm_payment_manager.json +++ b/corrugation/corrugation/doctype/cm_payment_manager/cm_payment_manager.json @@ -2,7 +2,7 @@ "allow_copy": 0, "allow_guest_to_view": 0, "allow_import": 0, - "allow_rename": 0, + "allow_rename": 1, "beta": 0, "creation": "2017-11-07 13:48:13.123185", "custom": 0, @@ -614,6 +614,36 @@ "search_index": 0, "set_only_once": 0, "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "amended_from", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Amended From", + "length": 0, + "no_copy": 1, + "options": "CM Payment Manager", + "permlevel": 0, + "print_hide": 1, + "print_hide_if_no_value": 0, + "read_only": 1, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 } ], "has_web_view": 0, @@ -622,11 +652,11 @@ "idx": 0, "image_view": 0, "in_create": 0, - "is_submittable": 0, + "is_submittable": 1, "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2017-11-15 15:33:27.555587", + "modified": "2017-11-15 20:00:43.389008", "modified_by": "Administrator", "module": "Corrugation", "name": "CM Payment Manager", @@ -634,9 +664,9 @@ "owner": "Administrator", "permissions": [ { - "amend": 0, + "amend": 1, "apply_user_permissions": 0, - "cancel": 0, + "cancel": 1, "create": 1, "delete": 1, "email": 1, @@ -650,7 +680,27 @@ "role": "System Manager", "set_user_permissions": 0, "share": 1, - "submit": 0, + "submit": 1, + "write": 1 + }, + { + "amend": 1, + "apply_user_permissions": 0, + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "if_owner": 0, + "import": 0, + "permlevel": 0, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts Manager", + "set_user_permissions": 0, + "share": 1, + "submit": 1, "write": 1 } ], diff --git a/corrugation/corrugation/doctype/cm_payment_manager/cm_payment_manager.py b/corrugation/corrugation/doctype/cm_payment_manager/cm_payment_manager.py index 164b8bb..a91d31a 100644 --- a/corrugation/corrugation/doctype/cm_payment_manager/cm_payment_manager.py +++ b/corrugation/corrugation/doctype/cm_payment_manager/cm_payment_manager.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import frappe +from frappe import _ from frappe.model.document import Document from erpnext.accounts.utils import get_outstanding_invoices from frappe.utils import nowdate @@ -138,6 +139,15 @@ def match_invoice_to_payment(self): def map_unknown_transactions(self): for entry in self.new_transaction_items: if (entry.party): continue + inv_type = "Sales Invoice" if (entry.amount > 0) else "Purchase Invoice" + party_type = "customer" if (entry.amount > 0) else "supplier" + + query = """select posting_date, name, {0}, grand_total + from `tab{1}` where grand_total={2} and posting_date < '{3}' + order by posting_date desc""".format(party_type, inv_type, abs(entry.amount), entry.transaction_date) + invoices = frappe.db.sql(query, as_dict = True) + if(len(invoices) > 0): + entry.party = invoices[0].get(party_type) def populate_matching_vouchers(self): for entry in self.new_transaction_items: @@ -186,7 +196,7 @@ def create_payment_entries(self): payment_entry.account = self.receivable_account if payment_entry.party_type == "Customer" else self.payable_account payment_entry.reference_name = payment.name payment_entry.reference_type = payment.doctype - msgprint(_("Successfully created payment entries")) + frappe.msgprint(_("Successfully created payment entries")) def create_payment_entry(self, pe): payment = frappe.new_doc("Payment Entry") @@ -220,19 +230,20 @@ def create_journal_entry(self, pe): je = frappe.new_doc("Journal Entry") je.is_opening = "No" je.voucher_type = "Bank Entry" + je.cheque_no = pe.description + je.cheque_date = pe.transaction_date je.remark = pe.description je.posting_date = pe.transaction_date if (pe.amount < 0): - je.append("accounts", {"account": pe.party, "debit_in_account_currency": pe.amount * -1}) - je.append("accounts", {"account": self.bank_account, "credit_in_account_currency": pe.amount * -1}) + je.append("accounts", {"account": pe.party, "debit_in_account_currency": abs(pe.amount)}) + je.append("accounts", {"account": self.bank_account, "credit_in_account_currency": abs(pe.amount)}) else: je.append("accounts", {"account": pe.party, "credit_in_account_currency": pe.amount}) je.append("accounts", {"account": self.bank_account, "debit_in_account_currency": pe.amount}) + je.save() + return je def update_payment_entry(self, payment): - if (payment.reference_type == "Journal Entry"): return - if frappe.db.get_value(payment.reference_type, payment.reference_name, "unallocated_amount") == 0: return - lst = [] invoices = payment.invoices.strip().split(',') if (len(invoices) == 0): return @@ -264,6 +275,8 @@ def submit_payment_entries(self): if payment.reference_name is None: continue doc = frappe.get_doc(payment.reference_type, payment.reference_name) if doc.docstatus == 1: + if (payment.reference_type == "Journal Entry"): continue + if doc.unallocated_amount == 0: continue print("Reconciling payment {0}".format(payment.reference_name)) self.update_payment_entry(payment) else: