Skip to content

Commit 7436d12

Browse files
committed
feat: pagar masivamente;
1 parent 3f38a98 commit 7436d12

File tree

2 files changed

+135
-2
lines changed

2 files changed

+135
-2
lines changed

erpnext/payroll/doctype/sales_commission/sales_commission.py

+78-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
22
# For license information, please see license.txt
3-
3+
import json
44
import frappe
55
from frappe import _
66
from frappe.model.document import Document
77
from frappe.utils import get_link_to_form
8+
from erpnext.accounts.general_ledger import make_gl_entries
89

910

1011
class SalesCommission(Document):
@@ -29,10 +30,70 @@ def validate_salary_component(self):
2930

3031
def on_submit(self):
3132
self.validate_amount()
33+
self.make_gl_entries()
3234
self.db_set("status", "Unpaid")
3335

3436
def on_cancel(self):
3537
self.ignore_linked_doctypes = ('GL Entry',)
38+
self.make_gl_entries(cancel=1)
39+
40+
def add_party_gl_entries(self, gl_entries):
41+
return
42+
if self.party_account:
43+
if self.payment_type=="Receive":
44+
against_account = self.paid_to
45+
else:
46+
against_account = self.paid_from
47+
48+
party_gl_dict = self.get_gl_dict({
49+
"account": self.party_account,
50+
"party_type": self.party_type,
51+
"party": self.party,
52+
"against": against_account,
53+
"account_currency": self.party_account_currency,
54+
"cost_center": self.cost_center
55+
}, item=self)
56+
57+
dr_or_cr = "credit" if erpnext.get_party_account_type(self.party_type) == 'Receivable' else "debit"
58+
59+
for d in self.get("references"):
60+
cost_center = self.cost_center
61+
if d.reference_doctype == "Sales Invoice" and not cost_center:
62+
cost_center = frappe.db.get_value(d.reference_doctype, d.reference_name, "cost_center")
63+
gle = party_gl_dict.copy()
64+
gle.update({
65+
"against_voucher_type": d.reference_doctype,
66+
"against_voucher": d.reference_name,
67+
"cost_center": cost_center
68+
})
69+
70+
allocated_amount_in_company_currency = flt(flt(d.allocated_amount) * flt(d.exchange_rate),
71+
self.precision("paid_amount"))
72+
73+
gle.update({
74+
dr_or_cr + "_in_account_currency": d.allocated_amount,
75+
dr_or_cr: allocated_amount_in_company_currency
76+
})
77+
78+
gl_entries.append(gle)
79+
80+
if self.unallocated_amount:
81+
exchange_rate = self.get_exchange_rate()
82+
base_unallocated_amount = (self.unallocated_amount * exchange_rate)
83+
84+
gle = party_gl_dict.copy()
85+
86+
gle.update({
87+
dr_or_cr + "_in_account_currency": self.unallocated_amount,
88+
dr_or_cr: base_unallocated_amount
89+
})
90+
91+
gl_entries.append(gle)
92+
93+
def make_gl_entries(self, cancel=0):
94+
gl_entries = []
95+
self.add_party_gl_entries(gl_entries)
96+
make_gl_entries(gl_entries, cancel=cancel)
3697

3798
@frappe.whitelist()
3899
def add_contributions(self, process_sales_commission):
@@ -166,3 +227,19 @@ def add_record(record, sales_person):
166227
if frappe.db.get_value("Sales Commission", {"name": contributions["parent"]}, fieldname=["sales_person"]) == sales_person:
167228
return False
168229
return True
230+
231+
232+
@frappe.whitelist()
233+
def payout_entries(names, mode_of_payment=None, reference_no=None, reference_date=None):
234+
if not frappe.has_permission("Sales Commission", "write"):
235+
frappe.throw(_("Not permitted"), frappe.PermissionError)
236+
237+
names = json.loads(names)
238+
for name in names:
239+
sales_commission = frappe.get_doc("Sales Commission", name)
240+
if sales_commission.docstatus != 1 or sales_commission.status == 'Paid':
241+
continue
242+
243+
sales_commission.payout_entry(mode_of_payment, reference_no, reference_date)
244+
245+
frappe.local.message_log = []

erpnext/payroll/doctype/sales_commission/sales_commission_list.js

+57-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,61 @@ frappe.listview_settings['Sales Commission'] = {
66
} else {
77
return [__(doc.status), "red", "status,=," + doc.status];
88
}
9+
},
10+
onload: function(listview){
11+
listview.page.add_actions_menu_item(__("Pagar Comisión"), function() {
12+
create_payment_entries();
13+
});
914
}
10-
};
15+
};
16+
17+
const create_payment_entries = function () {
18+
var d = new frappe.ui.Dialog({
19+
title: __("Select Mode of Payment"),
20+
fields: [
21+
{
22+
'fieldname': 'mode_of_payment',
23+
'fieldtype': 'Link',
24+
'label': __('Mode of Payment'),
25+
'options': 'Mode of Payment',
26+
"get_query": function () {
27+
return {
28+
filters: {
29+
type: ["in", ["Bank", "Cash"]]
30+
}
31+
};
32+
},
33+
'reqd': 1
34+
},
35+
{
36+
'fieldname': 'reference_no',
37+
'fieldtype': 'Data',
38+
'label': __('Número de referencia'),
39+
},
40+
{
41+
'fieldname': 'reference_date',
42+
'fieldtype': 'Date',
43+
'label': __('Fecha de referencia'),
44+
}
45+
],
46+
});
47+
d.set_primary_action(__('Create'), function() {
48+
d.hide();
49+
var arg = d.get_values();
50+
frappe.confirm(__("Creating Payment Entry. Do you want to proceed?"),
51+
function () {
52+
cur_list.call_for_selected_items("erpnext.payroll.doctype.sales_commission.sales_commission.payout_entries", {
53+
"mode_of_payment": arg.mode_of_payment,
54+
"reference_no": arg.reference_no,
55+
"reference_date": arg.reference_date
56+
});
57+
},
58+
function () {
59+
if (frappe.dom.freeze_count) {
60+
frappe.dom.unfreeze();
61+
}
62+
}
63+
);
64+
});
65+
d.show();
66+
};

0 commit comments

Comments
 (0)