From ea8e23384d3029569691e266700e3ebcdff6e17b Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 7 Mar 2023 11:40:29 +0530 Subject: [PATCH 1/3] fix: Payment Request against sales order with disabled rounded total (#34281) * fix: Payment Request against sales order with disabled rounded total * chore: Do not consider advance amount --- erpnext/accounts/doctype/payment_request/payment_request.py | 6 +----- .../doctype/payment_request/test_payment_request.py | 5 ++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 2f43914c45..7005c17362 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -495,26 +495,22 @@ def get_amount(ref_doc, payment_account=None): """get amount based on doctype""" dt = ref_doc.doctype if dt in ["Sales Order", "Purchase Order"]: - grand_total = flt(ref_doc.rounded_total) - flt(ref_doc.advance_paid) - + grand_total = flt(ref_doc.rounded_total) or flt(ref_doc.grand_total) elif dt in ["Sales Invoice", "Purchase Invoice"]: if ref_doc.party_account_currency == ref_doc.currency: grand_total = flt(ref_doc.outstanding_amount) else: grand_total = flt(ref_doc.outstanding_amount) / ref_doc.conversion_rate - elif dt == "POS Invoice": for pay in ref_doc.payments: if pay.type == "Phone" and pay.account == payment_account: grand_total = pay.amount break - elif dt == "Fees": grand_total = ref_doc.outstanding_amount if grand_total > 0: return grand_total - else: frappe.throw(_("Payment Entry is already created")) diff --git a/erpnext/accounts/doctype/payment_request/test_payment_request.py b/erpnext/accounts/doctype/payment_request/test_payment_request.py index 477c726940..4279aa4f85 100644 --- a/erpnext/accounts/doctype/payment_request/test_payment_request.py +++ b/erpnext/accounts/doctype/payment_request/test_payment_request.py @@ -45,7 +45,10 @@ class TestPaymentRequest(unittest.TestCase): frappe.get_doc(method).insert(ignore_permissions=True) def test_payment_request_linkings(self): - so_inr = make_sales_order(currency="INR") + so_inr = make_sales_order(currency="INR", do_not_save=True) + so_inr.disable_rounded_total = 1 + so_inr.save() + pr = make_payment_request( dt="Sales Order", dn=so_inr.name, From 7d0199d743c7861e883cadd582c036cc8d9b0a62 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 7 Mar 2023 11:41:26 +0530 Subject: [PATCH 2/3] fix: Default sales team not getting set (#34284) --- erpnext/controllers/selling_controller.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 8b4d28bc7d..e1f5062af0 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -84,6 +84,9 @@ class SellingController(StockController): ) if not self.meta.get_field("sales_team"): party_details.pop("sales_team") + else: + self.set("sales_team", party_details.get("sales_team")) + self.update_if_missing(party_details) elif lead: From 10632d75b049616525fb2810c94db8a7a53759b0 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 7 Mar 2023 11:44:09 +0530 Subject: [PATCH 3/3] fix: Do not calculate commission post submit (#34267) * fix: Do not calculate commision post submit * chore: Update condition to match server side logic Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --------- Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --- erpnext/controllers/selling_controller.py | 2 +- erpnext/selling/sales_common.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index e1f5062af0..3ea0216bb1 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -139,7 +139,7 @@ class SellingController(StockController): self.in_words = money_in_words(amount, self.currency) def calculate_commission(self): - if not self.meta.get_field("commission_rate"): + if not self.meta.get_field("commission_rate") or self.docstatus.is_submitted(): return self.round_floats_in(self, ("amount_eligible_for_commission", "commission_rate")) diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 5ce6e9c146..f1df3a11de 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -253,7 +253,7 @@ erpnext.selling.SellingController = class SellingController extends erpnext.Tran } calculate_commission() { - if(!this.frm.fields_dict.commission_rate) return; + if(!this.frm.fields_dict.commission_rate || this.frm.doc.docstatus === 1) return; if(this.frm.doc.commission_rate > 100) { this.frm.set_value("commission_rate", 100);