[Enhance] Fetch Customer's Item code based on Customer Name or Customer Group (#13198)

* customer code can be assigned based on customer group

* improvise customer group selection

* requested changes made
This commit is contained in:
Zarrar 2018-03-09 12:10:45 +05:30 committed by Nabin Hait
parent b2f7092f9e
commit 3fd634783d
4 changed files with 414 additions and 187 deletions

View File

@ -170,6 +170,35 @@ frappe.ui.form.on('Item Reorder', {
}
})
frappe.ui.form.on('Item Customer Detail', {
customer_items_add: function(frm, cdt, cdn) {
frappe.model.set_value(cdt, cdn, 'customer_group', "");
},
customer_name: function(frm, cdt, cdn) {
set_customer_group(frm, cdt, cdn);
},
customer_group: function(frm, cdt, cdn) {
if(set_customer_group(frm, cdt, cdn)){
frappe.msgprint(__("Changing Customer Group for the selected Customer is not allowed."));
}
}
});
var set_customer_group = function(frm, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
if (!row.customer_name) {
return false;
}
frappe.model.with_doc("Customer", row.customer_name, function() {
var customer = frappe.model.get_doc("Customer", row.customer_name);
row.customer_group = customer.customer_group;
refresh_field("customer_group", cdn, "customer_items");
});
return true;
}
$.extend(erpnext.item, {
setup_queries: function(frm) {
frm.fields_dict['expense_account'].get_query = function(doc) {

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
{
"allow_copy": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"autoname": "hash",
@ -12,16 +13,20 @@
"editable_grid": 1,
"fields": [
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 1,
"collapsible": 0,
"columns": 0,
"fieldname": "customer_name",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 1,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Customer Name",
"length": 0,
"no_copy": 0,
@ -33,24 +38,62 @@
"print_hide_if_no_value": 0,
"print_width": "180px",
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"reqd": 0,
"search_index": 1,
"set_only_once": 0,
"translatable": 0,
"unique": 0,
"width": "180px"
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 1,
"collapsible": 0,
"columns": 0,
"fieldname": "customer_group",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 1,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Customer Group",
"length": 0,
"no_copy": 0,
"options": "Customer Group",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "ref_code",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 1,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Ref Code",
"length": 0,
"no_copy": 0,
@ -61,25 +104,27 @@
"print_hide_if_no_value": 0,
"print_width": "120px",
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 1,
"set_only_once": 0,
"translatable": 0,
"unique": 0,
"width": "120px"
}
],
"has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 1,
"image_view": 0,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2016-07-11 03:28:00.992064",
"modified": "2018-03-08 14:22:38.019369",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item Customer Detail",
@ -88,5 +133,7 @@
"quick_entry": 0,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"track_changes": 0,
"track_seen": 0
}

View File

@ -396,8 +396,16 @@ def validate_conversion_rate(args, meta):
def get_party_item_code(args, item_doc, out):
if args.transaction_type=="selling" and args.customer:
out.customer_item_code = None
customer_item_code = item_doc.get("customer_items", {"customer_name": args.customer})
out.customer_item_code = customer_item_code[0].ref_code if customer_item_code else None
if customer_item_code:
out.customer_item_code = customer_item_code[0].ref_code
else:
customer_group = frappe.db.get_value("Customer", args.customer, "customer_group")
customer_group_item_code = item_doc.get("customer_items", {"customer_group": customer_group})
if customer_group_item_code and not customer_group_item_code[0].customer_name:
out.customer_item_code = customer_group_item_code[0].ref_code
if args.transaction_type=="buying" and args.supplier:
item_supplier = item_doc.get("supplier_items", {"supplier": args.supplier})