From 43f087c99da1a89373d1fe2310c76669bdf999ca Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 26 Aug 2014 14:25:53 +0530 Subject: [PATCH 1/4] [hotfix] Supplier read permission for Purchase User [Fix] Issue #448 [Fix] Issue #448 2 --- .../doctype/cost_center/cost_center.json | 4 +- .../purchase_invoice_item.json | 58 +++++++++---------- .../purchase_common/purchase_common.js | 2 +- erpnext/projects/doctype/project/project.json | 12 +++- erpnext/projects/doctype/project/project.py | 4 ++ erpnext/public/js/transaction.js | 3 +- erpnext/selling/sales_common.js | 18 ++++++ .../purchase_receipt_item.json | 22 +++---- erpnext/stock/get_item_details.py | 4 +- 9 files changed, 80 insertions(+), 47 deletions(-) diff --git a/erpnext/accounts/doctype/cost_center/cost_center.json b/erpnext/accounts/doctype/cost_center/cost_center.json index 36cb6ae7e9..e65f74bdb9 100644 --- a/erpnext/accounts/doctype/cost_center/cost_center.json +++ b/erpnext/accounts/doctype/cost_center/cost_center.json @@ -144,8 +144,8 @@ ], "icon": "icon-money", "idx": 1, - "in_create": 1, - "modified": "2014-05-27 03:49:08.910126", + "in_create": 0, + "modified": "2014-08-26 12:16:11.163750", "modified_by": "Administrator", "module": "Accounts", "name": "Cost Center", diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json index 22757430bf..d26dec0a92 100755 --- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json +++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json @@ -227,6 +227,17 @@ "fieldtype": "Column Break", "permlevel": 0 }, + { + "fieldname": "project_name", + "fieldtype": "Link", + "in_filter": 1, + "in_list_view": 0, + "label": "Project Name", + "options": "Project", + "permlevel": 0, + "print_hide": 1, + "read_only": 0 + }, { "default": ":Company", "fieldname": "cost_center", @@ -249,17 +260,6 @@ "label": "Reference", "permlevel": 0 }, - { - "fieldname": "project_name", - "fieldtype": "Link", - "in_filter": 1, - "in_list_view": 0, - "label": "Project Name", - "options": "Project", - "permlevel": 0, - "print_hide": 1, - "read_only": 0 - }, { "fieldname": "brand", "fieldtype": "Data", @@ -317,23 +317,6 @@ "search_index": 0, "width": "150px" }, - { - "allow_on_submit": 1, - "fieldname": "page_break", - "fieldtype": "Check", - "in_list_view": 0, - "label": "Page Break", - "no_copy": 1, - "permlevel": 0, - "print_hide": 1, - "read_only": 0, - "report_hide": 1 - }, - { - "fieldname": "col_break6", - "fieldtype": "Column Break", - "permlevel": 0 - }, { "fieldname": "purchase_order", "fieldtype": "Link", @@ -349,6 +332,11 @@ "read_only": 1, "search_index": 1 }, + { + "fieldname": "col_break6", + "fieldtype": "Column Break", + "permlevel": 0 + }, { "fieldname": "po_detail", "fieldtype": "Data", @@ -379,6 +367,18 @@ "read_only": 1, "search_index": 1 }, + { + "allow_on_submit": 1, + "fieldname": "page_break", + "fieldtype": "Check", + "in_list_view": 0, + "label": "Page Break", + "no_copy": 1, + "permlevel": 0, + "print_hide": 1, + "read_only": 0, + "report_hide": 1 + }, { "fieldname": "pr_detail", "fieldtype": "Data", @@ -421,7 +421,7 @@ ], "idx": 1, "istable": 1, - "modified": "2014-07-24 05:50:20.570629", + "modified": "2014-08-26 12:34:42.790959", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice Item", diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js index 3c63508991..c2e76e2ab7 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.js +++ b/erpnext/buying/doctype/purchase_common/purchase_common.js @@ -385,6 +385,6 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ }); } }); - +cur_frm.add_fetch('project_name', 'cost_center', 'cost_center'); var tname = cur_frm.cscript.tname; var fname = cur_frm.cscript.fname; diff --git a/erpnext/projects/doctype/project/project.json b/erpnext/projects/doctype/project/project.json index c7c459c5bc..f7a5754fb0 100644 --- a/erpnext/projects/doctype/project/project.json +++ b/erpnext/projects/doctype/project/project.json @@ -1,5 +1,6 @@ { - "allow_import": 1, + "allow_attach": 1, + "allow_import": 1, "allow_rename": 1, "autoname": "field:project_name", "creation": "2013-03-07 11:55:07", @@ -207,6 +208,13 @@ "permlevel": 0, "search_index": 0 }, + { + "fieldname": "cost_center", + "fieldtype": "Link", + "label": "Default Cost Center", + "options": "Cost Center", + "permlevel": 0 + }, { "fieldname": "column_break0", "fieldtype": "Column Break", @@ -265,7 +273,7 @@ "icon": "icon-puzzle-piece", "idx": 1, "max_attachments": 4, - "modified": "2014-08-04 03:22:11.416219", + "modified": "2014-08-26 14:59:27.052172", "modified_by": "Administrator", "module": "Projects", "name": "Project", diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index 547e12aebc..88e6e122fe 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -67,3 +67,7 @@ class Project(Document): def on_trash(self): delete_events(self.doctype, self.name) + +@frappe.whitelist() +def get_cost_center_name(project_name): + return frappe.db.get_value("Project", project_name, "cost_center") \ No newline at end of file diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js index 801ea57d21..4c0b341d48 100644 --- a/erpnext/public/js/transaction.js +++ b/erpnext/public/js/transaction.js @@ -151,7 +151,8 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ transaction_date: me.frm.doc.transaction_date, ignore_pricing_rule: me.frm.doc.ignore_pricing_rule, doctype: item.doctype, - name: item.name + name: item.name, + project_name: item.project_name || me.frm.doc.project_name } }, callback: function(r) { diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 20f1028d9a..8bb05c694f 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -585,3 +585,21 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ }); } }); + +frappe.ui.form.on(cur_frm.doctype,"project_name", function(frm) { + frappe.call({ + + method:'erpnext.projects.doctype.project.project.get_cost_center_name' , + args: { + project_name: frm.doc.project_name + }, + callback: function(r, rt) { + if(!r.exe) { + $.each(frm.doc[cur_frm.cscript.fname], function(i, row) { + frappe.model.set_value(row.doctype, row.name, "cost_center", r.message); + msgprint(__("Cost Center For Item with Item Code '"+row.item_name+"' has been Changed to "+ r.message)); + }) + } + } + }) +}) diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json index 0222e58da5..69c27556ce 100755 --- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json +++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json @@ -300,16 +300,6 @@ "read_only": 0, "width": "100px" }, - { - "default": ":Company", - "depends_on": "eval:cint(sys_defaults.auto_accounting_for_stock)", - "fieldname": "cost_center", - "fieldtype": "Link", - "label": "Cost Center", - "options": "Cost Center", - "permlevel": 0, - "print_hide": 1 - }, { "fieldname": "project_name", "fieldtype": "Link", @@ -320,6 +310,16 @@ "print_hide": 1, "read_only": 0 }, + { + "default": ":Company", + "depends_on": "eval:cint(sys_defaults.auto_accounting_for_stock)", + "fieldname": "cost_center", + "fieldtype": "Link", + "label": "Cost Center", + "options": "Cost Center", + "permlevel": 0, + "print_hide": 1 + }, { "fieldname": "qa_no", "fieldtype": "Link", @@ -557,7 +557,7 @@ ], "idx": 1, "istable": 1, - "modified": "2014-08-11 12:48:13.509109", + "modified": "2014-08-26 12:38:04.065982", "modified_by": "Administrator", "module": "Stock", "name": "Purchase Receipt Item", diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index efb793deea..fffb52e835 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -29,6 +29,7 @@ def get_item_details(args): "is_subcontracted": "Yes" / "No", "transaction_type": "selling", "ignore_pricing_rule": 0/1 + "project_name": "", } """ args = process_args(args) @@ -149,7 +150,8 @@ def get_basic_details(args, item_doc): or args.expense_account or frappe.db.get_value("Item Group", item.item_group, "default_expense_account") or frappe.db.get_value("Company", args.company, "default_expense_account")), - "cost_center": ((item.selling_cost_center if args.transaction_type == "selling" else item.buying_cost_center) + "cost_center": (frappe.db.get_value("Project", args.project_name, "cost_center") + or (item.selling_cost_center if args.transaction_type == "selling" else item.buying_cost_center) or frappe.db.get_value("Item Group", item.item_group, "default_cost_center") or frappe.db.get_value("Company", args.company, "cost_center")), "batch_no": None, From 3b1733bc044942689baa3ef456c485a205272fb9 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 26 Aug 2014 16:20:38 +0530 Subject: [PATCH 2/4] minor fix in sales invoice test records --- erpnext/accounts/doctype/sales_invoice/test_records.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/test_records.json b/erpnext/accounts/doctype/sales_invoice/test_records.json index eb86672ccd..76c70cc416 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_records.json +++ b/erpnext/accounts/doctype/sales_invoice/test_records.json @@ -17,6 +17,7 @@ "description": "138-CMS Shoe", "doctype": "Sales Invoice Item", "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", "item_name": "138-CMS Shoe", "parentfield": "entries", "qty": 1.0, @@ -137,6 +138,7 @@ "cost_center": "_Test Cost Center - _TC", "doctype": "Sales Invoice Item", "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", "item_code": "_Test Item Home Desktop 100", "item_name": "_Test Item Home Desktop 100", "item_tax_rate": "{\"_Test Account Excise Duty - _TC\": 10}", @@ -150,6 +152,7 @@ "cost_center": "_Test Cost Center - _TC", "doctype": "Sales Invoice Item", "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", "item_code": "_Test Item Home Desktop 200", "item_name": "_Test Item Home Desktop 200", "parentfield": "entries", @@ -261,6 +264,7 @@ "cost_center": "_Test Cost Center - _TC", "doctype": "Sales Invoice Item", "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", "item_code": "_Test Item Home Desktop 100", "item_name": "_Test Item Home Desktop 100", "item_tax_rate": "{\"_Test Account Excise Duty - _TC\": 10}", @@ -273,6 +277,7 @@ "cost_center": "_Test Cost Center - _TC", "doctype": "Sales Invoice Item", "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", "item_code": "_Test Item Home Desktop 200", "item_name": "_Test Item Home Desktop 200", "parentfield": "entries", From ad24069cdc10e0232d94d704c4b7cbf04b8a3529 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Tue, 26 Aug 2014 16:27:59 +0530 Subject: [PATCH 3/4] [fix] issue 448 final --- erpnext/public/js/transaction.js | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js index 4c0b341d48..d5209c1874 100644 --- a/erpnext/public/js/transaction.js +++ b/erpnext/public/js/transaction.js @@ -155,6 +155,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ project_name: item.project_name || me.frm.doc.project_name } }, + callback: function(r) { if(!r.exc) { me.frm.script_manager.trigger("price_list_rate", cdt, cdn); From d6d71e8078a3c50a39dc2071ebc7b62bc030fa25 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Wed, 27 Aug 2014 18:48:57 +0530 Subject: [PATCH 4/4] [fix] issue 448 final 1 --- erpnext/selling/sales_common.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 8bb05c694f..66e935ab6f 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -588,16 +588,13 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ frappe.ui.form.on(cur_frm.doctype,"project_name", function(frm) { frappe.call({ - method:'erpnext.projects.doctype.project.project.get_cost_center_name' , - args: { - project_name: frm.doc.project_name - }, + args: { project_name: frm.doc.project_name }, callback: function(r, rt) { - if(!r.exe) { - $.each(frm.doc[cur_frm.cscript.fname], function(i, row) { + if(!r.exc) { + $.each(frm.doc[cur_frm.cscript.fname] || [], function(i, row) { frappe.model.set_value(row.doctype, row.name, "cost_center", r.message); - msgprint(__("Cost Center For Item with Item Code '"+row.item_name+"' has been Changed to "+ r.message)); + msgprint(__("Cost Center For Item with Item Code '"+row.item_name+"' has been Changed to "+ r.message)); }) } }