From e6aa3b435ae7fc88059340de23911816493e60cc Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 9 Feb 2017 17:47:22 +0530 Subject: [PATCH] [minor] added make material request from Stock Entry and removed cur_frm --- .../profit_and_loss_statement.py | 31 +- .../doctype/purchase_order/purchase_order.js | 2 +- .../stock/doctype/stock_entry/stock_entry.js | 398 +++++++++--------- 3 files changed, 223 insertions(+), 208 deletions(-) diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py index 747eb43006..254523f03f 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py +++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py @@ -9,12 +9,12 @@ from erpnext.accounts.report.financial_statements import (get_period_list, get_c def execute(filters=None): period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, filters.periodicity) - + income = get_data(filters.company, "Income", "Credit", period_list, filters = filters, accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True) expense = get_data(filters.company, "Expense", "Debit", period_list, filters=filters, accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True) - + net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company) data = [] @@ -24,7 +24,7 @@ def execute(filters=None): data.append(net_profit_loss) columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company) - + chart = get_chart_data(filters, columns, income, expense, net_profit_loss) return columns, data, None, chart @@ -43,21 +43,21 @@ def get_net_profit_loss(income, expense, period_list, company): for period in period_list: net_profit_loss[period.key] = flt(income[-2][period.key] - expense[-2][period.key], 3) - + if net_profit_loss[period.key]: has_value=True - + total += flt(net_profit_loss[period.key]) net_profit_loss["total"] = total - + if has_value: return net_profit_loss def get_chart_data(filters, columns, income, expense, net_profit_loss): x_intervals = ['x'] + [d.get("label") for d in columns[2:]] - + income_data, expense_data, net_profit = [], [], [] - + for p in columns[2:]: if income: income_data.append(income[-2].get(p.get("fieldname"))) @@ -65,7 +65,7 @@ def get_chart_data(filters, columns, income, expense, net_profit_loss): expense_data.append(expense[-2].get(p.get("fieldname"))) if net_profit_loss: net_profit.append(net_profit_loss.get(p.get("fieldname"))) - + columns = [x_intervals] if income_data: columns.append(["Income"] + income_data) @@ -73,15 +73,20 @@ def get_chart_data(filters, columns, income, expense, net_profit_loss): columns.append(["Expense"] + expense_data) if net_profit: columns.append(["Net Profit/Loss"] + net_profit) - + chart = { "data": { 'x': 'x', - 'columns': columns + 'columns': columns, + 'colors': { + 'Income': '#5E64FF', + 'Expense': '#b8c2cc', + 'Net Profit/Loss': '#ff5858' + } } } - + if not filters.accumulated_values: chart["chart_type"] = "bar" - + return chart \ No newline at end of file diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index f2f04fe88c..0a577c3c1b 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -66,7 +66,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend( if(doc.docstatus == 1 && doc.status != "Closed") { if(flt(doc.per_received, 2) < 100 && allow_receipt) { - cur_frm.add_custom_button(__('Receive'), this.make_purchase_receipt, __("Make")); + cur_frm.add_custom_button(__('Receipt'), this.make_purchase_receipt, __("Make")); if(doc.is_subcontracted==="Yes") { cur_frm.add_custom_button(__('Material to Supplier'), diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 37f9b680bf..ed044a92c9 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -2,6 +2,188 @@ frappe.provide("erpnext.stock"); +frappe.ui.form.on('Stock Entry', { + setup: function(frm) { + $.extend(frm.cscript, new erpnext.stock.StockEntry({frm: frm})); + + frm.set_query('production_order', function() { + return { + filters: [ + ['Production Order', 'docstatus', '=', 1], + ['Production Order', 'qty', '>','`tabProduction Order`.produced_qty'], + ['Production Order', 'company', '=', frm.doc.company] + ] + } + }); + // }, + // onload_post_render: function(frm) { + + frm.set_query('batch_no', 'items', function(doc, cdt, cdn) { + var item = locals[cdt][cdn]; + if(!item.item_code) { + frappe.throw(__("Please enter Item Code to get Batch Number")); + } else { + if (in_list(["Material Transfer for Manufacture", "Manufacture", "Repack", "Subcontract"], doc.purpose)) { + var filters = { + 'item_code': item.item_code, + 'posting_date': frm.doc.posting_date || nowdate() + } + } else { + var filters = { + 'item_code': item.item_code + } + } + + if(item.s_warehouse) filters["warehouse"] = item.s_warehouse; + return { + query : "erpnext.controllers.queries.get_batch_no", + filters: filters + } + } + }); + }, + refresh: function(frm) { + if(!frm.doc.docstatus) { + frm.add_custom_button(__('Make Material Request'), function() { + frappe.model.with_doctype('Material Request', function() { + var mr = frappe.model.get_new_doc('Material Request'); + var items = frm.get_field('items').grid.get_selected_children(); + if(!items.length) { + items = frm.doc.items; + } + items.forEach(function(item) { + var mr_item = frappe.model.add_child(mr, 'items'); + mr_item.item_code = item.item_code; + mr_item.item_name = item.item_name; + mr_item.uom = item.uom; + mr_item.item_group = item.item_group; + mr_item.description = item.description; + mr_item.image = item.image; + mr_item.qty = item.qty; + mr_item.warehouse = item.s_warehouse; + mr_item.required_date = frappe.datetime.nowdate(); + }); + frappe.set_route('Form', 'Material Request', mr.name); + }); + }); + } + }, + purpose: function(frm) { + frm.fields_dict.items.grid.refresh(); + frm.cscript.toggle_related_fields(frm.doc); + }, + company: function(frm) { + if(frm.doc.company) { + var company_doc = frappe.get_doc(":Company", frm.doc.company); + if(company_doc.default_letter_head) { + frm.set_value("letter_head", company_doc.default_letter_head); + } + } + }, + set_serial_no: function(frm, cdt, cdn) { + var d = frappe.model.get_doc(cdt, cdn); + if(!d.item_code && !d.s_warehouse && !d.qty) return; + var args = { + 'item_code' : d.item_code, + 'warehouse' : cstr(d.s_warehouse), + 'qty' : d.qty + }; + frappe.call({ + method: "erpnext.stock.get_item_details.get_serial_no", + args: {"args": args}, + callback: function(r) { + if (!r.exe){ + frappe.model.set_value(cdt, cdn, "serial_no", r.message); + } + } + }); + }, +}) + +frappe.ui.form.on('Stock Entry Detail', { + qty: function(frm, cdt, cdn) { + frm.events.set_serial_no(frm, cdt, cdn); + }, + + s_warehouse: function(frm, cdt, cdn) { + frm.events.set_serial_no(frm, cdt, cdn); + }, + barcode: function(doc, cdt, cdn) { + var d = locals[cdt][cdn]; + if (d.barcode) { + frappe.call({ + method: "erpnext.stock.get_item_details.get_item_code", + args: {"barcode": d.barcode }, + callback: function(r) { + if (!r.exe){ + frappe.model.set_value(cdt, cdn, "item_code", r.message); + } + } + }); + } + }, + uom: function(doc, cdt, cdn) { + var d = locals[cdt][cdn]; + if(d.uom && d.item_code){ + return frappe.call({ + method: "erpnext.stock.doctype.stock_entry.stock_entry.get_uom_details", + args: { + item_code: d.item_code, + uom: d.uom, + qty: d.qty + }, + callback: function(r) { + if(r.message) { + frappe.model.set_value(cdt, cdn, r.message); + } + } + }); + } + }, + item_code: function(frm, cdt, cdn) { + var d = locals[cdt][cdn]; + if(d.item_code) { + args = { + 'item_code' : d.item_code, + 'warehouse' : cstr(d.s_warehouse) || cstr(d.t_warehouse), + 'transfer_qty' : d.transfer_qty, + 'serial_no ' : d.serial_no, + 'bom_no' : d.bom_no, + 'expense_account' : d.expense_account, + 'cost_center' : d.cost_center, + 'company' : frm.doc.company, + 'qty' : d.qty + }; + return frappe.call({ + doc: frm.doc, + method: "get_item_details", + args: args, + callback: function(r) { + if(r.message) { + var d = locals[cdt][cdn]; + $.each(r.message, function(k, v) { + d[k] = v; + }); + refresh_field("items"); + } + } + }); + } + }, + expense_account: function(frm, cdt, cdn) { + erpnext.utils.copy_value_in_all_row(frm.doc, cdt, cdn, "items", "expense_account"); + }, + cost_center: function(doc, cdt, cdn) { + erpnext.utils.copy_value_in_all_row(frm.doc, cdt, cdn, "items", "cost_center"); + } +}); + +frappe.ui.form.on('Landed Cost Taxes and Charges', { + amount: function(frm) { + frm.events.calculate_amount(); + } +}); + erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ setup: function() { var me = this; @@ -51,7 +233,7 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ var me = this; this.set_default_account(function() { if(me.frm.doc.__islocal && me.frm.doc.company && !me.frm.doc.amended_from) { - cur_frm.script_manager.trigger("company"); + me.frm.trigger("company"); } }); @@ -180,7 +362,7 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ excise.voucher_type = 'Excise Entry'; frappe.set_route('Form', 'Journal Entry', excise.name); }, __("Make")); - cur_frm.page.set_inner_btn_group_as_primary(__("Make")); + this.frm.page.set_inner_btn_group_as_primary(__("Make")); }, items_add: function(doc, cdt, cdn) { @@ -309,204 +491,32 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ this.frm.set_value("total_additional_costs", flt(total_additional_costs, precision("total_additional_costs"))); }, -}); -cur_frm.script_manager.make(erpnext.stock.StockEntry); + toggle_related_fields: function(doc) { + this.frm.toggle_enable("from_warehouse", doc.purpose!='Material Receipt'); + this.frm.toggle_enable("to_warehouse", doc.purpose!='Material Issue'); -cur_frm.cscript.toggle_related_fields = function(doc) { - cur_frm.toggle_enable("from_warehouse", doc.purpose!='Material Receipt'); - cur_frm.toggle_enable("to_warehouse", doc.purpose!='Material Issue'); + this.frm.fields_dict["items"].grid.set_column_disp("s_warehouse", doc.purpose!='Material Receipt'); + this.frm.fields_dict["items"].grid.set_column_disp("t_warehouse", doc.purpose!='Material Issue'); - cur_frm.fields_dict["items"].grid.set_column_disp("s_warehouse", doc.purpose!='Material Receipt'); - cur_frm.fields_dict["items"].grid.set_column_disp("t_warehouse", doc.purpose!='Material Issue'); + this.frm.cscript.toggle_enable_bom(); - cur_frm.cscript.toggle_enable_bom(); - - if (doc.purpose == 'Subcontract') { - doc.customer = doc.customer_name = doc.customer_address = - doc.delivery_note_no = doc.sales_invoice_no = null; - } else { - doc.customer = doc.customer_name = doc.customer_address = - doc.delivery_note_no = doc.sales_invoice_no = doc.supplier = - doc.supplier_name = doc.supplier_address = doc.purchase_receipt_no = null; - } - if(doc.purpose == "Material Receipt") { - cur_frm.set_value("from_bom", 0); - } - - // Addition costs based on purpose - cur_frm.toggle_display(["additional_costs", "total_additional_costs", "additional_costs_section"], - doc.purpose!='Material Issue'); - - cur_frm.fields_dict["items"].grid.set_column_disp("additional_cost", doc.purpose!='Material Issue'); -} - -cur_frm.fields_dict['production_order'].get_query = function(doc) { - return { - filters: [ - ['Production Order', 'docstatus', '=', 1], - ['Production Order', 'qty', '>','`tabProduction Order`.produced_qty'], - ['Production Order', 'company', '=', cur_frm.doc.company] - ] - } -} - -cur_frm.cscript.purpose = function(doc, cdt, cdn) { - cur_frm.fields_dict.items.grid.refresh(); - cur_frm.cscript.toggle_related_fields(doc); -} - -// Overloaded query for link batch_no -cur_frm.fields_dict['items'].grid.get_field('batch_no').get_query = function(doc, cdt, cdn) { - var item = locals[cdt][cdn]; - if(!item.item_code) { - frappe.throw(__("Please enter Item Code to get batch no")); - } - else { - if (in_list(["Material Transfer for Manufacture", "Manufacture", "Repack", "Subcontract"], doc.purpose)) { - var filters = { - 'item_code': item.item_code, - 'posting_date': me.frm.doc.posting_date || nowdate() - } + if (doc.purpose == 'Subcontract') { + doc.customer = doc.customer_name = doc.customer_address = + doc.delivery_note_no = doc.sales_invoice_no = null; } else { - var filters = { - 'item_code': item.item_code - } + doc.customer = doc.customer_name = doc.customer_address = + doc.delivery_note_no = doc.sales_invoice_no = doc.supplier = + doc.supplier_name = doc.supplier_address = doc.purchase_receipt_no = null; + } + if(doc.purpose == "Material Receipt") { + frm.set_value("from_bom", 0); } + // Addition costs based on purpose + this.frm.toggle_display(["additional_costs", "total_additional_costs", "additional_costs_section"], + doc.purpose!='Material Issue'); - if(item.s_warehouse) filters["warehouse"] = item.s_warehouse - return { - query : "erpnext.controllers.queries.get_batch_no", - filters: filters - } + this.frm.fields_dict["items"].grid.set_column_disp("additional_cost", doc.purpose!='Material Issue'); } -} - -cur_frm.cscript.validate = function(doc, cdt, cdn) { - cur_frm.cscript.validate_items(doc); -} - -cur_frm.cscript.validate_items = function(doc) { - cl = doc.items || []; - if (!cl.length) { - msgprint(__("Item table can not be blank")); - validated = false; - } -} - -cur_frm.cscript.expense_account = function(doc, cdt, cdn) { - erpnext.utils.copy_value_in_all_row(doc, cdt, cdn, "items", "expense_account"); -} - -cur_frm.cscript.cost_center = function(doc, cdt, cdn) { - erpnext.utils.copy_value_in_all_row(doc, cdt, cdn, "items", "cost_center"); -} - - -frappe.ui.form.on('Landed Cost Taxes and Charges', { - amount: function(frm) { - frm.cscript.calculate_amount(); - } -}) - -frappe.ui.form.on('Stock Entry Detail', { - qty: function(frm, cdt, cdn) { - frm.events.set_serial_no(frm, cdt, cdn); - }, - - s_warehouse: function(frm, cdt, cdn) { - frm.events.set_serial_no(frm, cdt, cdn); - }, - barcode: function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; - if (d.barcode) { - frappe.call({ - method: "erpnext.stock.get_item_details.get_item_code", - args: {"barcode": d.barcode }, - callback: function(r) { - if (!r.exe){ - frappe.model.set_value(cdt, cdn, "item_code", r.message); - } - } - }); - } - }, - uom: function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; - if(d.uom && d.item_code){ - return frappe.call({ - method: "erpnext.stock.doctype.stock_entry.stock_entry.get_uom_details", - args: { - item_code: d.item_code, - uom: d.uom, - qty: d.qty - }, - callback: function(r) { - if(r.message) { - frappe.model.set_value(cdt, cdn, r.message); - } - } - }); - } - }, - item_code: function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; - if(d.item_code) { - args = { - 'item_code' : d.item_code, - 'warehouse' : cstr(d.s_warehouse) || cstr(d.t_warehouse), - 'transfer_qty' : d.transfer_qty, - 'serial_no ' : d.serial_no, - 'bom_no' : d.bom_no, - 'expense_account' : d.expense_account, - 'cost_center' : d.cost_center, - 'company' : cur_frm.doc.company, - 'qty' : d.qty - }; - return frappe.call({ - doc: cur_frm.doc, - method: "get_item_details", - args: args, - callback: function(r) { - if(r.message) { - var d = locals[cdt][cdn]; - $.each(r.message, function(k, v) { - d[k] = v; - }); - refresh_field("items"); - } - } - }); - } - } -}) - -frappe.ui.form.on('Stock Entry', { - company: function(doc, cdt, cdn) { - if(doc.company) { - var company_doc = frappe.get_doc(":Company", doc.company); - if(company_doc.default_letter_head) { - cur_frm.set_value("letter_head", company_doc.default_letter_head); - } - } - }, - set_serial_no: function(doc, cdt, cdn) { - var d = frappe.model.get_doc(cdt, cdn); - if(!d.item_code && !d.s_warehouse && !d.qty) return; - var args = { - 'item_code' : d.item_code, - 'warehouse' : cstr(d.s_warehouse), - 'qty' : d.qty - }; - frappe.call({ - method: "erpnext.stock.get_item_details.get_serial_no", - args: {"args": args}, - callback: function(r) { - if (!r.exe){ - frappe.model.set_value(cdt, cdn, "serial_no", r.message); - } - } - }); - }, -}) +}); \ No newline at end of file