From c7a11cc451acfb3afa701cd72af99bd131d4edac Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 19 Feb 2015 16:28:35 +0530 Subject: [PATCH] [usability] [fixes] stock entry and production order --- .../purchase_order/purchase_order_list.js | 3 +- .../production_order/production_order.js | 34 ++++--- .../production_order/production_order.py | 12 +-- erpnext/patches.txt | 1 + .../patches/v5_0/stock_entry_update_value.py | 7 ++ .../doctype/sales_order/sales_order_list.js | 3 +- .../stock/doctype/stock_entry/stock_entry.js | 2 +- .../doctype/stock_entry/stock_entry.json | 38 +++++++- .../stock/doctype/stock_entry/stock_entry.py | 10 +++ .../stock_entry_detail.json | 90 +++++++++---------- erpnext/stock/stock_ledger.py | 2 +- .../maintenance_visit/maintenance_visit.js | 2 +- .../doctype/warranty_claim/warranty_claim.js | 2 +- .../templates/form_grid/stock_entry_grid.html | 38 ++++---- 14 files changed, 157 insertions(+), 87 deletions(-) create mode 100644 erpnext/patches/v5_0/stock_entry_update_value.py diff --git a/erpnext/buying/doctype/purchase_order/purchase_order_list.js b/erpnext/buying/doctype/purchase_order/purchase_order_list.js index 1b27b79922..2c28eec2c5 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order_list.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order_list.js @@ -11,5 +11,6 @@ frappe.listview_settings['Purchase Order'] = { } else if(flt(doc.per_received) == 100 && flt(doc.per_billed) == 100 && doc.status!=="Stopped") { return [__("Completed"), "green", "per_received,=,100|per_billed,=,100|status,!=,Stopped"]; } - } + }, + order_by: "per_received asc, modified desc" }; diff --git a/erpnext/manufacturing/doctype/production_order/production_order.js b/erpnext/manufacturing/doctype/production_order/production_order.js index f7f3e87df3..3f4e99e538 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.js +++ b/erpnext/manufacturing/doctype/production_order/production_order.js @@ -151,18 +151,30 @@ $.extend(cur_frm.cscript, { make_se: function(purpose) { var me = this; + var max = (purpose === "Manufacture") ? + flt(this.frm.doc.material_transferred_for_qty) - flt(this.frm.doc.produced_qty) : + flt(this.frm.doc.qty) - flt(this.frm.doc.material_transferred_for_qty); - frappe.call({ - method:"erpnext.manufacturing.doctype.production_order.production_order.make_stock_entry", - args: { - "production_order_id": me.frm.doc.name, - "purpose": purpose - }, - callback: function(r) { - var doclist = frappe.model.sync(r.message); - frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } - }); + frappe.prompt({fieldtype:"Int", label: __("Qty for {0}", [purpose]), fieldname:"qty", + description: __("Max: {0}", [max]) }, + function(data) { + if(data.qty > max) { + frappe.msgprint(__("Quantity must not be more than {0}", [max])); + return; + } + frappe.call({ + method:"erpnext.manufacturing.doctype.production_order.production_order.make_stock_entry", + args: { + "production_order_id": me.frm.doc.name, + "purpose": purpose, + "qty": data.qty + }, + callback: function(r) { + var doclist = frappe.model.sync(r.message); + frappe.set_route("Form", doclist[0].doctype, doclist[0].name); + } + }); + }, __("Select Quantity"), __("Make")); }, bom_no: function() { diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py index 480d5ef5bd..b7f2ba9724 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.py +++ b/erpnext/manufacturing/doctype/production_order/production_order.py @@ -123,17 +123,17 @@ class ProductionOrder(Document): def update_production_order_qty(self): """Update **Manufactured Qty** and **Material Transferred for Qty** in Production Order based on Stock Entry""" - for status, fieldname in (("Manufacture", "produced_qty"), + for purpose, fieldname in (("Manufacture", "produced_qty"), ("Material Transfer for Manufacture", "material_transferred_for_qty")): qty = flt(frappe.db.sql("""select sum(fg_completed_qty) from `tabStock Entry` where production_order=%s and docstatus=1 - and purpose=%s""", (self.name, status))[0][0]) + and purpose=%s""", (self.name, purpose))[0][0]) - if qty > self.qty: - frappe.throw(_("{0} ({1}) cannot be greater than planned quanitity ({2}) in Production Order {3}").format(\ - self.meta.get_label(fieldname), qty, self.qty, self.name), StockOverProductionError) + if qty > self.qty: + frappe.throw(_("{0} ({1}) cannot be greater than planned quanitity ({2}) in Production Order {3}").format(\ + self.meta.get_label(fieldname), qty, self.qty, self.name), StockOverProductionError) - self.db_set(fieldname, qty) + self.db_set(fieldname, qty) def on_submit(self): if not self.wip_warehouse: diff --git a/erpnext/patches.txt b/erpnext/patches.txt index e444eec4e9..17e6435429 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -119,3 +119,4 @@ erpnext.patches.v5_0.update_material_transfer_for_manufacture erpnext.patches.v5_0.manufacturing_activity_type erpnext.patches.v5_0.update_item_description_and_image erpnext.patches.v5_0.update_material_transferred_for_qty +erpnext.patches.v5_0.stock_entry_update_value diff --git a/erpnext/patches/v5_0/stock_entry_update_value.py b/erpnext/patches/v5_0/stock_entry_update_value.py new file mode 100644 index 0000000000..9abd315ff1 --- /dev/null +++ b/erpnext/patches/v5_0/stock_entry_update_value.py @@ -0,0 +1,7 @@ +import frappe + +def execute(): + for d in frappe.db.get_all("Stock Entry"): + se = frappe.get_doc("Stock Entry", d.name) + se.set_total_incoming_outgoing_value() + se.db_update() diff --git a/erpnext/selling/doctype/sales_order/sales_order_list.js b/erpnext/selling/doctype/sales_order/sales_order_list.js index 17681a366f..702c300ac5 100644 --- a/erpnext/selling/doctype/sales_order/sales_order_list.js +++ b/erpnext/selling/doctype/sales_order/sales_order_list.js @@ -13,5 +13,6 @@ frappe.listview_settings['Sales Order'] = { } else if(flt(doc.per_delivered) == 100 && flt(doc.per_billed) == 100 && doc.status!=="Stopped") { return [__("Completed"), "green", "per_delivered,=,100|per_billed,=,100|status,!=,Stopped"]; } - } + }, + order_by: "per_delivered asc, modified desc" }; diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index f738c4a790..8795524c82 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -147,7 +147,7 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ refresh_field('items'); calculate_total(doc, cdt, cdn); }, - + incoming_rate: function(doc, cdt, cdn) { calculate_total(doc, cdt, cdn); }, diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.json b/erpnext/stock/doctype/stock_entry/stock_entry.json index ac6e94b0d7..bcbfb0187d 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.json +++ b/erpnext/stock/doctype/stock_entry/stock_entry.json @@ -265,6 +265,42 @@ "print_hide": 1, "read_only": 0 }, + { + "fieldname": "section_break_19", + "fieldtype": "Section Break", + "permlevel": 0, + "precision": "" + }, + { + "fieldname": "total_incoming_value", + "fieldtype": "Currency", + "label": "Total Incoming Value", + "permlevel": 0, + "precision": "", + "read_only": 1 + }, + { + "fieldname": "column_break_22", + "fieldtype": "Column Break", + "permlevel": 0, + "precision": "" + }, + { + "fieldname": "total_outgoing_value", + "fieldtype": "Currency", + "label": "Total Outgoing Value", + "permlevel": 0, + "precision": "", + "read_only": 1 + }, + { + "fieldname": "value_difference", + "fieldtype": "Currency", + "label": "Total Value Difference (Out - In)", + "permlevel": 0, + "precision": "", + "read_only": 1 + }, { "depends_on": "eval:(doc.purpose!==\"Sales Return\" && doc.purpose!==\"Purchase Return\")", "fieldname": "sb1", @@ -596,7 +632,7 @@ "is_submittable": 1, "issingle": 0, "max_attachments": 0, - "modified": "2015-02-17 00:49:04.294855", + "modified": "2015-02-19 04:53:05.361046", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry", diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 16d045b40d..8d9f405be1 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -221,6 +221,16 @@ class StockEntry(StockController): frappe.throw(_("Total valuation ({0}) for manufactured or repacked item(s) can not be less than total valuation of raw materials ({1})").format(valuation_at_target, valuation_at_source)) + def set_total_incoming_outgoing_value(self): + self.total_incoming_value = self.total_outgoing_value = 0.0 + for d in self.get("items"): + if d.s_warehouse: + self.total_incoming_value += flt(d.amount) + if d.t_warehouse: + self.total_outgoing_value += flt(d.amount) + + self.value_difference = self.total_outgoing_value - self.total_incoming_value + def set_total_amount(self): self.total_amount = sum([flt(item.amount) for item in self.get("items")]) diff --git a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json index 216be2980c..750e7d68eb 100644 --- a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json +++ b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json @@ -60,12 +60,15 @@ "permlevel": 0 }, { - "fieldname": "item_name", - "fieldtype": "Data", - "label": "Item Name", + "fieldname": "qty", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Qty", + "oldfieldname": "qty", + "oldfieldtype": "Currency", "permlevel": 0, - "print_hide": 1, - "read_only": 1 + "read_only": 0, + "reqd": 1 }, { "fieldname": "section_break_8", @@ -73,6 +76,14 @@ "permlevel": 0, "precision": "" }, + { + "fieldname": "item_name", + "fieldtype": "Data", + "label": "Item Name", + "permlevel": 0, + "print_hide": 1, + "read_only": 1 + }, { "fieldname": "description", "fieldtype": "Text", @@ -115,15 +126,31 @@ "permlevel": 0 }, { - "fieldname": "qty", - "fieldtype": "Float", + "fieldname": "incoming_rate", + "fieldtype": "Currency", "in_list_view": 1, - "label": "Qty", - "oldfieldname": "qty", + "label": "Valuation Rate", + "oldfieldname": "incoming_rate", "oldfieldtype": "Currency", + "options": "Company:company:default_currency", "permlevel": 0, "read_only": 0, - "reqd": 1 + "reqd": 0 + }, + { + "fieldname": "amount", + "fieldtype": "Currency", + "label": "Amount", + "oldfieldname": "amount", + "oldfieldtype": "Currency", + "options": "Company:company:default_currency", + "permlevel": 0, + "read_only": 1 + }, + { + "fieldname": "col_break3", + "fieldtype": "Column Break", + "permlevel": 0 }, { "fieldname": "uom", @@ -138,21 +165,15 @@ "reqd": 1 }, { - "fieldname": "incoming_rate", - "fieldtype": "Currency", - "in_list_view": 1, - "label": "Valuation Rate", - "oldfieldname": "incoming_rate", + "fieldname": "conversion_factor", + "fieldtype": "Float", + "label": "Conversion Factor", + "oldfieldname": "conversion_factor", "oldfieldtype": "Currency", - "options": "Company:company:default_currency", "permlevel": 0, - "read_only": 0, - "reqd": 0 - }, - { - "fieldname": "col_break3", - "fieldtype": "Column Break", - "permlevel": 0 + "print_hide": 1, + "read_only": 1, + "reqd": 1 }, { "fieldname": "stock_uom", @@ -168,27 +189,6 @@ "reqd": 1, "search_index": 0 }, - { - "fieldname": "conversion_factor", - "fieldtype": "Float", - "label": "Conversion Factor", - "oldfieldname": "conversion_factor", - "oldfieldtype": "Currency", - "permlevel": 0, - "print_hide": 1, - "read_only": 1, - "reqd": 1 - }, - { - "fieldname": "amount", - "fieldtype": "Currency", - "label": "Amount", - "oldfieldname": "amount", - "oldfieldtype": "Currency", - "options": "Company:company:default_currency", - "permlevel": 0, - "read_only": 1 - }, { "fieldname": "serial_no_batch", "fieldtype": "Section Break", @@ -331,7 +331,7 @@ ], "idx": 1, "istable": 1, - "modified": "2015-02-19 01:07:02.254835", + "modified": "2015-02-19 05:33:06.289852", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry Detail", diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 7340baf78d..0f63a643ea 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -99,7 +99,7 @@ class update_entries_after(object): self.precision = get_field_precision(frappe.get_meta("Stock Ledger Entry").get_field("stock_value"), currency=frappe.db.get_value("Company", self.company, "default_currency")) - self.prev_stock_value = self.stock_value + self.prev_stock_value = self.previous_sle.stock_value or 0.0 self.stock_queue = json.loads(self.previous_sle.stock_queue or "[]") self.valuation_method = get_valuation_method(self.item_code) self.stock_value_difference = 0.0 diff --git a/erpnext/support/doctype/maintenance_visit/maintenance_visit.js b/erpnext/support/doctype/maintenance_visit/maintenance_visit.js index 5427b0f5f6..28c88efa7c 100644 --- a/erpnext/support/doctype/maintenance_visit/maintenance_visit.js +++ b/erpnext/support/doctype/maintenance_visit/maintenance_visit.js @@ -30,7 +30,7 @@ erpnext.support.MaintenanceVisit = frappe.ui.form.Controller.extend({ cur_frm.add_custom_button(__('From Warranty Claim'), function() { frappe.model.map_current_doc({ - method: "erpnext.support.doctype.customer_issue.customer_issue.make_maintenance_visit", + method: "erpnext.support.doctype.warranty_claim.warranty_claim.make_maintenance_visit", source_doctype: "Warranty Claim", get_query_filters: { status: ["in", "Open, Work in Progress"], diff --git a/erpnext/support/doctype/warranty_claim/warranty_claim.js b/erpnext/support/doctype/warranty_claim/warranty_claim.js index e06255960e..0d6d6f531f 100644 --- a/erpnext/support/doctype/warranty_claim/warranty_claim.js +++ b/erpnext/support/doctype/warranty_claim/warranty_claim.js @@ -21,7 +21,7 @@ erpnext.support.WarrantyClaim = frappe.ui.form.Controller.extend({ make_maintenance_visit: function() { frappe.model.open_mapped_doc({ - method: "erpnext.support.doctype.customer_issue.customer_issue.make_maintenance_visit", + method: "erpnext.support.doctype.warranty_claim.warranty_claim.make_maintenance_visit", frm: cur_frm }) } diff --git a/erpnext/templates/form_grid/stock_entry_grid.html b/erpnext/templates/form_grid/stock_entry_grid.html index ef465a4860..089a6e84e2 100644 --- a/erpnext/templates/form_grid/stock_entry_grid.html +++ b/erpnext/templates/form_grid/stock_entry_grid.html @@ -5,32 +5,34 @@ {% if(!doc) { %}
-
{%= __("Item") %}
+
{%= __("Item") %}
+
{%= __("Warehouse") %}
{%= __("Qty") %}
-
{%= __("Amount") %}
+
{%= __("Amount") %}
{% } else { %}
-
{%= doc.item_code %} +
{%= doc.item_code %} {% if(doc.item_name != doc.item_code) { %}
{%= doc.item_name %}{% } %} {% if(doc.item_name != doc.description) { %}

{%= doc.description %}

{% } %} {% include "templates/form_grid/includes/visible_cols.html" %} -
- {% if(doc.s_warehouse) { %} - - {%= doc.s_warehouse || "" %} - {% } %} - - {% if(doc.t_warehouse) { %} - {%= doc.t_warehouse || "" %}{% } %} - {% if(doc.s_warehouse && doc.actual_qty < doc.qty) { %} - - Not in Stock - - {% } %} -
+ {% if(frm.doc.docstatus==0 && doc.s_warehouse && doc.actual_qty < doc.qty) { %} + + Not in Stock + + {% } %} +
+ + +
+ {% if(doc.s_warehouse) { %} + + {%= doc.s_warehouse || "" %} + {% } %} + {% if(doc.t_warehouse) { %} + {%= doc.t_warehouse || "" %}{% } %}
@@ -40,7 +42,7 @@
-
+
{%= doc.get_formatted("amount") %}
{%= doc.get_formatted("incoming_rate") %}