From 5b05335e89a581ddb74176effd956ba9084fef7c Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 7 Sep 2017 15:14:09 +0530 Subject: [PATCH] added patch and set default fields after completion of setup wizard --- erpnext/patches.txt | 1 + .../v8_9/set_default_fields_in_variant_settings.py | 13 +++++++++++++ erpnext/setup/setup_wizard/setup_wizard.py | 7 +++++++ .../item_variant_settings/item_variant_settings.js | 5 ++++- .../item_variant_settings.json | 8 ++++---- .../item_variant_settings/item_variant_settings.py | 13 ++++++++++++- .../test_item_variant_settings.py | 9 +++++++++ 7 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 erpnext/patches/v8_9/set_default_fields_in_variant_settings.py create mode 100644 erpnext/stock/doctype/item_variant_settings/test_item_variant_settings.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index f961a5b81e..855358e716 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -446,3 +446,4 @@ erpnext.patches.v8_9.set_print_zero_amount_taxes erpnext.patches.v8_9.set_default_customer_group erpnext.patches.v8_9.remove_employee_from_salary_structure_parent erpnext.patches.v8_9.delete_gst_doctypes_for_outside_india_accounts +erpnext.patches.v8_9.set_default_fields_in_variant_settings \ No newline at end of file diff --git a/erpnext/patches/v8_9/set_default_fields_in_variant_settings.py b/erpnext/patches/v8_9/set_default_fields_in_variant_settings.py new file mode 100644 index 0000000000..a550d093fa --- /dev/null +++ b/erpnext/patches/v8_9/set_default_fields_in_variant_settings.py @@ -0,0 +1,13 @@ +# Copyright (c) 2017, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + frappe.reload_doc('stock', 'doctype', 'item_variant_settings') + frappe.reload_doc('stock', 'doctype', 'variant_field') + + doc = frappe.get_doc('Item Variant Settings') + doc.set_default_fields() + doc.save() \ No newline at end of file diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index d3e4a084f5..bf9221784c 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -33,6 +33,7 @@ def setup_complete(args=None): create_feed_and_todo() create_email_digest() create_letter_head(args) + set_no_copy_fields_in_variant_settings() if args.get('domain').lower() == 'education': create_academic_year() @@ -354,6 +355,12 @@ def create_letter_head(args): fileurl = save_file(filename, content, "Letter Head", _("Standard"), decode=True).file_url frappe.db.set_value("Letter Head", _("Standard"), "content", "" % fileurl) +def set_no_copy_fields_in_variant_settings(): + # set no copy fields of an item doctype to item variant settings + doc = frappe.get_doc('Item Variant Settings') + doc.set_default_fields() + doc.save() + def create_logo(args): if args.get("attach_logo"): attach_logo = args.get("attach_logo").split(",") diff --git a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js index cd7d8a4085..77ccfd0cc0 100644 --- a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js +++ b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js @@ -4,9 +4,12 @@ frappe.ui.form.on('Item Variant Settings', { setup: function(frm) { const allow_fields = []; + const exclude_fields = ["item_code", "item_name", "show_in_website", "show_variant_in_website", "standard_rate"]; + frappe.model.with_doctype('Item', () => { frappe.get_meta('Item').fields.forEach(d => { - if(!in_list(['HTML', 'Section Break', 'Column Break', 'Button'], d.fieldtype) && !d.no_copy) { + if(!in_list(['HTML', 'Section Break', 'Column Break', 'Button'], d.fieldtype) + && !d.no_copy && !in_list(exclude_fields, d.fieldname)) { allow_fields.push(d.fieldname); } }); diff --git a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.json b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.json index 226a07ca6f..a29137c762 100644 --- a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.json +++ b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.json @@ -18,7 +18,7 @@ "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "variant_fields", + "fieldname": "copy_fields_to_variant", "fieldtype": "Section Break", "hidden": 0, "ignore_user_permissions": 0, @@ -27,7 +27,7 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Variant Fields", + "label": "Copy Fields to Variant", "length": 0, "no_copy": 0, "permlevel": 0, @@ -84,8 +84,8 @@ "issingle": 1, "istable": 0, "max_attachments": 0, - "modified": "2017-08-29 16:38:49.467749", - "modified_by": "Administrator", + "modified": "2017-09-11 12:05:16.288601", + "modified_by": "rohit@erpnext.com", "module": "Stock", "name": "Item Variant Settings", "name_case": "", diff --git a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.py b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.py index 26e08d119d..1cc7c21520 100644 --- a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.py +++ b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.py @@ -3,7 +3,18 @@ # For license information, please see license.txt from __future__ import unicode_literals +import frappe from frappe.model.document import Document class ItemVariantSettings(Document): - pass + def set_default_fields(self): + self.fields = [] + fields = frappe.get_meta('Item').fields + exclude_fields = ["item_code", "item_name", "show_in_website", "show_variant_in_website", "standard_rate"] + + for d in fields: + if not d.no_copy and d.fieldname not in exclude_fields and \ + d.fieldtype not in ['HTML', 'Section Break', 'Column Break', 'Button']: + self.append('fields', { + 'field_name': d.fieldname + }) \ No newline at end of file diff --git a/erpnext/stock/doctype/item_variant_settings/test_item_variant_settings.py b/erpnext/stock/doctype/item_variant_settings/test_item_variant_settings.py new file mode 100644 index 0000000000..9a800c07fc --- /dev/null +++ b/erpnext/stock/doctype/item_variant_settings/test_item_variant_settings.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +import unittest + +class TestItemVariantSettings(unittest.TestCase): + pass