Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetching details from supplier/customer groups #26131

Merged
merged 8 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions erpnext/buying/doctype/supplier/supplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,23 @@ frappe.ui.form.on("Supplier", {
erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name);
}, __('Create'));

frm.add_custom_button(__('Get Supplier Group Details'), function () {
frm.trigger("get_supplier_group_details");
}, __('Actions'));

// indicators
erpnext.utils.set_party_dashboard_indicators(frm);
}
},
get_supplier_group_details: function(frm) {
frappe.call({
method: "get_supplier_group_details",
doc: frm.doc,
callback: function() {
frm.refresh();
}
});
},

is_internal_supplier: function(frm) {
if (frm.doc.is_internal_supplier == 1) {
Expand Down
19 changes: 18 additions & 1 deletion erpnext/buying/doctype/supplier/supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ def validate(self):
validate_party_accounts(self)
self.validate_internal_supplier()

@frappe.whitelist()
def get_supplier_group_details(self):
doc = frappe.get_doc('Supplier Group', self.supplier_group)
self.payment_terms = ""
self.accounts = []

if doc.accounts:
for account in doc.accounts:
child = self.append('accounts')
child.company = account.company
child.account = account.account

if doc.payment_terms:
self.payment_terms = doc.payment_terms

self.save()

def validate_internal_supplier(self):
internal_supplier = frappe.db.get_value("Supplier",
{"is_internal_supplier": 1, "represents_company": self.represents_company, "name": ("!=", self.name)}, "name")
Expand Down Expand Up @@ -86,4 +103,4 @@ def create_onboarding_docs(self, args):
create_contact(supplier, 'Supplier',
doc.name, args.get('supplier_email_' + str(i)))
except frappe.NameError:
pass
pass
26 changes: 25 additions & 1 deletion erpnext/buying/doctype/supplier/test_supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@


class TestSupplier(unittest.TestCase):
def test_get_supplier_group_details(self):
doc = frappe.new_doc("Supplier Group")
doc.supplier_group_name = "_Testing Supplier Group"
doc.payment_terms = "_Test Payment Term Template 3"
doc.accounts = []
test_account_details = {
"company": "_Test Company",
"account": "Creditors - _TC",
}
doc.append("accounts", test_account_details)
doc.save()
s_doc = frappe.new_doc("Supplier")
s_doc.supplier_name = "Testing Supplier"
s_doc.supplier_group = "_Testing Supplier Group"
s_doc.payment_terms = ""
s_doc.accounts = []
s_doc.insert()
s_doc.get_supplier_group_details()
self.assertEqual(s_doc.payment_terms, "_Test Payment Term Template 3")
self.assertEqual(s_doc.accounts[0].company, "_Test Company")
self.assertEqual(s_doc.accounts[0].account, "Creditors - _TC")
s_doc.delete()
doc.delete()

def test_supplier_default_payment_terms(self):
# Payment Term based on Days after invoice date
frappe.db.set_value(
Expand Down Expand Up @@ -136,4 +160,4 @@ def create_supplier(**args):
return doc

except frappe.DuplicateEntryError:
return frappe.get_doc("Supplier", args.supplier_name)
return frappe.get_doc("Supplier", args.supplier_name)
17 changes: 16 additions & 1 deletion erpnext/selling/doctype/customer/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ frappe.ui.form.on("Customer", {
erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name);
}, __('Create'));

frm.add_custom_button(__('Get Customer Group Details'), function () {
frm.trigger("get_customer_group_details");
}, __('Actions'));

// indicator
erpnext.utils.set_party_dashboard_indicators(frm);

Expand All @@ -145,4 +149,15 @@ frappe.ui.form.on("Customer", {
if(frm.doc.lead_name) frappe.model.clear_doc("Lead", frm.doc.lead_name);

},
});
get_customer_group_details: function(frm) {
frappe.call({
method: "get_customer_group_details",
doc: frm.doc,
callback: function() {
frm.refresh();
}
});

}
});

23 changes: 23 additions & 0 deletions erpnext/selling/doctype/customer/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ def validate(self):
if sum(member.allocated_percentage or 0 for member in self.sales_team) != 100:
frappe.throw(_("Total contribution percentage should be equal to 100"))

@frappe.whitelist()
def get_customer_group_details(self):
doc = frappe.get_doc('Customer Group', self.customer_group)
self.accounts = self.credit_limits = []
self.payment_terms = self.default_price_list = ""

tables = [["accounts", "account"], ["credit_limits", "credit_limit"]]
fields = ["payment_terms", "default_price_list"]

for row in tables:
table, field = row[0], row[1]
if not doc.get(table): continue

for entry in doc.get(table):
child = self.append(table)
child.update({"company": entry.company, field: entry.get(field)})

for field in fields:
if not doc.get(field): continue
self.update({field: doc.get(field)})

self.save()

def check_customer_group_change(self):
frappe.flags.customer_group_changed = False

Expand Down
36 changes: 36 additions & 0 deletions erpnext/selling/doctype/customer/test_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,42 @@ def setUp(self):
def tearDown(self):
set_credit_limit('_Test Customer', '_Test Company', 0)

def test_get_customer_group_details(self):
doc = frappe.new_doc("Customer Group")
doc.customer_group_name = "_Testing Customer Group"
doc.payment_terms = "_Test Payment Term Template 3"
doc.accounts = []
doc.default_price_list = "Standard Buying"
doc.credit_limits = []
test_account_details = {
"company": "_Test Company",
"account": "Creditors - _TC",
}
test_credit_limits = {
"company": "_Test Company",
"credit_limit": 350000
}
doc.append("accounts", test_account_details)
doc.append("credit_limits", test_credit_limits)
doc.insert()

c_doc = frappe.new_doc("Customer")
c_doc.customer_name = "Testing Customer"
c_doc.customer_group = "_Testing Customer Group"
c_doc.payment_terms = c_doc.default_price_list = ""
c_doc.accounts = c_doc.credit_limits= []
c_doc.insert()
c_doc.get_customer_group_details()
self.assertEqual(c_doc.payment_terms, "_Test Payment Term Template 3")

self.assertEqual(c_doc.accounts[0].company, "_Test Company")
self.assertEqual(c_doc.accounts[0].account, "Creditors - _TC")

self.assertEqual(c_doc.credit_limits[0].company, "_Test Company")
self.assertEqual(c_doc.credit_limits[0].credit_limit, 350000)
c_doc.delete()
doc.delete()

def test_party_details(self):
from erpnext.accounts.party import get_party_details

Expand Down