Skip to content

Commit 5ebe5ed

Browse files
committed
feat: oustanding
1 parent 5a1b5e7 commit 5ebe5ed

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

erpnext/accounts/doctype/payment_entry/payment_entry.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,15 @@ def update_sales_commission(self, cancel=0):
889889
if self.payment_type in ("Pay") and self.party:
890890
for d in self.get("references"):
891891
if d.reference_doctype=="Sales Commission" and d.reference_name:
892+
outstanding_amount = frappe.get_value("Sales Commission", d.reference_name, "outstanding_amount")
892893
if cancel:
894+
outstanding_amount += d.allocated_amount
895+
else:
896+
outstanding_amount -= d.allocated_amount
897+
898+
frappe.db.set_value("Sales Commission", d.reference_name, "outstanding_amount", outstanding_amount)
899+
900+
if outstanding_amount > 0:
893901
frappe.db.set_value("Sales Commission", d.reference_name, "status", "Unpaid")
894902
else:
895903
frappe.db.set_value("Sales Commission", d.reference_name, "status", "Paid")
@@ -1460,7 +1468,7 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre
14601468
elif reference_doctype != "Journal Entry":
14611469
if ref_doc.doctype == "Sales Commission":
14621470
total_amount = ref_doc.total_commission_amount
1463-
outstanding_amount = ref_doc.total_commission_amount
1471+
outstanding_amount = ref_doc.get("outstanding_amount")
14641472
exchange_rate = 1
14651473
if ref_doc.doctype == "Expense Claim":
14661474
total_amount = flt(ref_doc.total_sanctioned_amount) + flt(ref_doc.total_taxes_and_charges)
@@ -1497,7 +1505,7 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre
14971505
elif reference_doctype == "Gratuity":
14981506
outstanding_amount = ref_doc.amount - flt(ref_doc.paid_amount)
14991507
elif reference_doctype == "Sales Commission":
1500-
outstanding_amount = ref_doc.total_commission_amount
1508+
outstanding_amount = ref_doc.get("outstanding_amount")
15011509
else:
15021510
outstanding_amount = flt(total_amount) - flt(ref_doc.advance_paid)
15031511
else:

erpnext/payroll/doctype/sales_commission/sales_commission.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ frappe.ui.form.on('Sales Commission', {
7272
create_additional_salary(frm);
7373
}).addClass("btn-primary");
7474
} else {
75-
frm.add_custom_button(__("Create Payment Entry"), function () {
76-
create_payment_entry(frm);
77-
}).addClass("btn-primary");
75+
if (frm.doc.status == "Unpaid") {
76+
frm.add_custom_button(__("Create Payment Entry"), function () {
77+
create_payment_entry(frm);
78+
}).addClass("btn-primary");
79+
}
80+
7881
}
7982
}
8083
},

erpnext/payroll/doctype/sales_commission/sales_commission.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"section_break_17",
3434
"total_contribution",
3535
"total_commission_amount",
36+
"outstanding_amount",
3637
"remarks",
3738
"column_break_21",
3839
"commission_rate",
@@ -258,12 +259,18 @@
258259
"fieldtype": "Dynamic Link",
259260
"label": "Filtro",
260261
"options": "commission_against"
262+
},
263+
{
264+
"fieldname": "outstanding_amount",
265+
"fieldtype": "Currency",
266+
"label": "Outstanding Amount",
267+
"read_only": 1
261268
}
262269
],
263270
"index_web_pages_for_search": 1,
264271
"is_submittable": 1,
265272
"links": [],
266-
"modified": "2024-11-04 08:47:23.231953",
273+
"modified": "2024-11-04 11:23:05.322965",
267274
"modified_by": "Administrator",
268275
"module": "Payroll",
269276
"name": "Sales Commission",

erpnext/payroll/doctype/sales_commission/sales_commission.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def calculate_total_contribution_and_total_commission_amount(self):
178178

179179
self.total_contribution = total_contribution
180180
self.total_commission_amount = total_commission_amount
181+
self.outstanding_amount = total_commission_amount
181182

182183
@frappe.whitelist()
183184
def payout_entry(self, mode_of_payment=None, reference_no=None, reference_date=None):
@@ -241,25 +242,22 @@ def make_payment_entry(self, mode_of_payment, paid_from, paid_to, reference_no,
241242
doc.party = self.employee
242243
doc.paid_from = paid_from
243244
doc.paid_to = paid_to
244-
doc.paid_amount = self.total_commission_amount
245-
doc.received_amount = self.total_commission_amount
245+
doc.paid_amount = self.outstanding_amount
246+
doc.received_amount = self.outstanding_amount
246247
doc.source_exchange_rate = 1
247248
doc.target_exchange_rate = 1
248249
doc.set("references", [])
249250
self.add_references(doc)
250251
doc.submit()
251-
# self.db_set("reference_doctype", "Payment Entry")
252-
# self.db_set("reference_name", doc.name)
253-
# self.db_set("status", "Paid")
254252

255253
def add_references(self, doc):
256254
reference = {
257255
'reference_doctype': 'Sales Commission',
258256
'reference_name': self.name,
259257
'due_date': self.to_date,
260258
'total_amount': self.total_commission_amount,
261-
'outstanding_amount': self.total_commission_amount,
262-
'allocated_amount': self.total_commission_amount,
259+
'outstanding_amount': self.outstanding_amount,
260+
'allocated_amount': self.outstanding_amount,
263261
}
264262
doc.append("references", reference)
265263

0 commit comments

Comments
 (0)