fix: create payment entry against payment request

This commit is contained in:
Mangesh-Khairnar 2020-10-04 13:01:11 +05:30
parent 8d12c3841f
commit 1bef6a530c
5 changed files with 35 additions and 30 deletions

View File

@ -950,12 +950,12 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre
@frappe.whitelist() @frappe.whitelist()
def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=None): def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=None, mode_of_payment=None):
doc = frappe.get_doc(dt, dn) doc = frappe.get_doc(dt, dn)
if dt in ("Sales Order", "Purchase Order") and flt(doc.per_billed, 2) > 0: if dt in ("Sales Order", "Purchase Order") and flt(doc.per_billed, 2) > 0:
frappe.throw(_("Can only make payment against unbilled {0}").format(dt)) frappe.throw(_("Can only make payment against unbilled {0}").format(dt))
if dt in ("Sales Invoice", "Sales Order", "Dunning"): if dt in ("Sales Invoice", "Sales Order", "Dunning", "POS Invoice"):
party_type = "Customer" party_type = "Customer"
elif dt in ("Purchase Invoice", "Purchase Order"): elif dt in ("Purchase Invoice", "Purchase Order"):
party_type = "Supplier" party_type = "Supplier"
@ -965,7 +965,7 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
party_type = "Student" party_type = "Student"
# party account # party account
if dt == "Sales Invoice": if dt in ["Sales Invoice", "POS Invoice"]:
party_account = get_party_account_based_on_invoice_discounting(dn) or doc.debit_to party_account = get_party_account_based_on_invoice_discounting(dn) or doc.debit_to
elif dt == "Purchase Invoice": elif dt == "Purchase Invoice":
party_account = doc.credit_to party_account = doc.credit_to
@ -984,7 +984,7 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
party_account_currency = doc.get("party_account_currency") or get_account_currency(party_account) party_account_currency = doc.get("party_account_currency") or get_account_currency(party_account)
# payment type # payment type
if (dt == "Sales Order" or (dt in ("Sales Invoice", "Fees", "Dunning") and doc.outstanding_amount > 0)) \ if (dt == "Sales Order" or (dt in ("Sales Invoice", "Fees", "Dunning", "POS Invoice") and doc.outstanding_amount > 0)) \
or (dt=="Purchase Invoice" and doc.outstanding_amount < 0): or (dt=="Purchase Invoice" and doc.outstanding_amount < 0):
payment_type = "Receive" payment_type = "Receive"
else: else:
@ -994,7 +994,7 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
grand_total = outstanding_amount = 0 grand_total = outstanding_amount = 0
if party_amount: if party_amount:
grand_total = outstanding_amount = party_amount grand_total = outstanding_amount = party_amount
elif dt in ("Sales Invoice", "Purchase Invoice"): elif dt in ("Sales Invoice", "Purchase Invoice", "POS Invoice"):
if party_account_currency == doc.company_currency: if party_account_currency == doc.company_currency:
grand_total = doc.base_rounded_total or doc.base_grand_total grand_total = doc.base_rounded_total or doc.base_grand_total
else: else:
@ -1021,11 +1021,11 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
outstanding_amount = grand_total - flt(doc.advance_paid) outstanding_amount = grand_total - flt(doc.advance_paid)
# bank or cash # bank or cash
bank = get_default_bank_cash_account(doc.company, "Bank", mode_of_payment=doc.get("mode_of_payment"), bank = get_default_bank_cash_account(doc.company, "Bank", mode_of_payment=doc.get("mode_of_payment", mode_of_payment),
account=bank_account) account=bank_account)
if not bank: if not bank:
bank = get_default_bank_cash_account(doc.company, "Cash", mode_of_payment=doc.get("mode_of_payment"), bank = get_default_bank_cash_account(doc.company, "Cash", mode_of_payment=doc.get("mode_of_payment", mode_of_payment),
account=bank_account) account=bank_account)
paid_amount = received_amount = 0 paid_amount = received_amount = 0
@ -1050,7 +1050,7 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
pe.company = doc.company pe.company = doc.company
pe.cost_center = doc.get("cost_center") pe.cost_center = doc.get("cost_center")
pe.posting_date = nowdate() pe.posting_date = nowdate()
pe.mode_of_payment = doc.get("mode_of_payment") pe.mode_of_payment = doc.get("mode_of_payment", mode_of_payment)
pe.party_type = party_type pe.party_type = party_type
pe.party = doc.get(scrub(party_type)) pe.party = doc.get(scrub(party_type))
pe.contact_person = doc.get("contact_person") pe.contact_person = doc.get("contact_person")

View File

@ -165,7 +165,7 @@ class PaymentRequest(Document):
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name) ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
if self.reference_doctype == "Sales Invoice": if self.reference_doctype in ["Sales Invoice", "POS Invoice"]:
party_account = ref_doc.debit_to party_account = ref_doc.debit_to
elif self.reference_doctype == "Purchase Invoice": elif self.reference_doctype == "Purchase Invoice":
party_account = ref_doc.credit_to party_account = ref_doc.credit_to
@ -180,8 +180,8 @@ class PaymentRequest(Document):
else: else:
party_amount = self.grand_total party_amount = self.grand_total
payment_entry = get_payment_entry(self.reference_doctype, self.reference_name, payment_entry = get_payment_entry(self.reference_doctype, self.reference_name, party_amount=party_amount,
party_amount=party_amount, bank_account=self.payment_account, bank_amount=bank_amount) bank_account=self.payment_account, bank_amount=bank_amount, mode_of_payment=self.mode_of_payment)
payment_entry.update({ payment_entry.update({
"reference_no": self.name, "reference_no": self.name,
@ -269,7 +269,7 @@ class PaymentRequest(Document):
# if shopping cart enabled and in session # if shopping cart enabled and in session
if (shopping_cart_settings.enabled and hasattr(frappe.local, "session") if (shopping_cart_settings.enabled and hasattr(frappe.local, "session")
and frappe.local.session.user != "Guest"): and frappe.local.session.user != "Guest") and self.payment_channel != "Phone":
success_url = shopping_cart_settings.payment_success_url success_url = shopping_cart_settings.payment_success_url
if success_url: if success_url:

View File

@ -316,8 +316,13 @@ class POSInvoice(SalesInvoice):
def create_payment_request(self): def create_payment_request(self):
for pay in self.payments: for pay in self.payments:
if pay.type == "Phone": if pay.type == "Phone":
if pay.amount <= 0:
frappe.throw(_("Payment amount cannot be less than or equal to 0"))
if not self.contact_mobile:
frappe.throw(_("Please enter the phone number first"))
payment_gateway = frappe.db.get_value("Payment Gateway Account", { payment_gateway = frappe.db.get_value("Payment Gateway Account", {
"payment_account": pay.account, "payment_account": pay.account,
}) })

View File

@ -43,7 +43,7 @@ def get_webhook_address(connector_name, method, exclude_uri=False):
return server_url return server_url
def create_mode_of_payment(gateway): def create_mode_of_payment(gateway, payment_type="General"):
payment_gateway_account = frappe.db.get_value("Payment Gateway Account", { payment_gateway_account = frappe.db.get_value("Payment Gateway Account", {
"payment_gateway": gateway "payment_gateway": gateway
}, ['payment_account']) }, ['payment_account'])
@ -53,11 +53,11 @@ def create_mode_of_payment(gateway):
"doctype": "Mode of Payment", "doctype": "Mode of Payment",
"mode_of_payment": gateway, "mode_of_payment": gateway,
"enabled": 1, "enabled": 1,
"type": "General", "type": payment_type,
"account": { "accounts": [{
"doctype": "Mode of Payment Account", "doctype": "Mode of Payment Account",
"company": get_default_company(), "company": get_default_company(),
"default_account": payment_gateway_account "default_account": payment_gateway_account
} }]
}) })
mode_of_payment.insert(ignore_permissions=True) mode_of_payment.insert(ignore_permissions=True)

View File

@ -175,21 +175,21 @@ erpnext.PointOfSale.Payment = class {
}) })
frappe.realtime.on("process_phone_payments", function(data) { frappe.realtime.on("process_phone_payments", function(data) {
frappe.msgprint({message: 'help', title:'now'}) frappe.dom.unfreeze();
// frappe.dom.unfreeze(); let message = data["ResultDesc"];
// let message = data["ResultDesc"]; let title = __("Payment Failed");
// let title = __("Payment Failed"); const frm = me.events.get_frm();
// const frm = me.events.get_frm();
// if (data["ResultCode"] == 0) { if (data["ResultCode"] == 0) {
// title = __("Payment Received"); title = __("Payment Received");
// $('[data-fieldname=request_for_payment]').text("Paid") $('[data-fieldname=request_for_payment]').text("Paid")
// } cur_pos.submit()
}
// frappe.msgprint({ frappe.msgprint({
// "message": message, "message": message,
// "title": title "title": title
// }); });
}); });
this.$payment_modes.on('click', '.shortcut', function(e) { this.$payment_modes.on('click', '.shortcut', function(e) {