From 1dfcc7557ae44cf669b1d1829ba1ae7c575f6651 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Tue, 15 Oct 2013 13:54:39 +0530 Subject: [PATCH 01/11] [fix] fetch difference account and cost center on selecting item in stock entry --- .../doctype/sales_invoice/sales_invoice.js | 23 ++--- stock/doctype/stock_entry/stock_entry.js | 86 +++++++++++++------ stock/doctype/stock_entry/stock_entry.py | 6 +- 3 files changed, 71 insertions(+), 44 deletions(-) diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index 46e336f029..4d4f4b7ee0 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -349,7 +349,7 @@ if (sys_defaults.auto_accounting_for_stock) { // warehouse in detail table //---------------------------- -cur_frm.fields_dict['entries'].grid.get_field('warehouse').get_query= function(doc, cdt, cdn) { +cur_frm.fields_dict['entries'].grid.get_field('warehouse').get_query = function(doc, cdt, cdn) { var d = locals[cdt][cdn]; return{ filters:[ @@ -370,36 +370,29 @@ cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = functio } } -cur_frm.cscript.income_account = function(doc, cdt, cdn){ +cur_frm.cscript.income_account = function(doc, cdt, cdn) { cur_frm.cscript.copy_account_in_all_row(doc, cdt, cdn, "income_account"); } -cur_frm.cscript.expense_account = function(doc, cdt, cdn){ +cur_frm.cscript.expense_account = function(doc, cdt, cdn) { cur_frm.cscript.copy_account_in_all_row(doc, cdt, cdn, "expense_account"); } +cur_frm.cscript.cost_center = function(doc, cdt, cdn) { + cur_frm.cscript.copy_account_in_all_row(doc, cdt, cdn, "cost_center"); +} + cur_frm.cscript.copy_account_in_all_row = function(doc, cdt, cdn, fieldname) { var d = locals[cdt][cdn]; if(d[fieldname]){ var cl = getchildren('Sales Invoice Item', doc.name, cur_frm.cscript.fname, doc.doctype); - for(var i = 0; i < cl.length; i++){ + for(var i = 0; i < cl.length; i++) { if(!cl[i][fieldname]) cl[i][fieldname] = d[fieldname]; } } refresh_field(cur_frm.cscript.fname); } -cur_frm.cscript.cost_center = function(doc, cdt, cdn){ - var d = locals[cdt][cdn]; - if(d.cost_center){ - var cl = getchildren('Sales Invoice Item', doc.name, cur_frm.cscript.fname, doc.doctype); - for(var i = 0; i < cl.length; i++){ - if(!cl[i].cost_center) cl[i].cost_center = d.cost_center; - } - } - refresh_field(cur_frm.cscript.fname); -} - cur_frm.cscript.on_submit = function(doc, cdt, cdn) { if(cint(wn.boot.notification_settings.sales_invoice)) { cur_frm.email_doc(wn.boot.notification_settings.sales_invoice_message); diff --git a/stock/doctype/stock_entry/stock_entry.js b/stock/doctype/stock_entry/stock_entry.js index 4695fdb22c..26ad62925a 100644 --- a/stock/doctype/stock_entry/stock_entry.js +++ b/stock/doctype/stock_entry/stock_entry.js @@ -1,6 +1,9 @@ // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. // License: GNU General Public License v3. See license.txt +cur_frm.cscript.tname = "Stock Entry Detail"; +cur_frm.cscript.fname = "mtn_details"; + wn.require("public/app/js/controllers/stock_controller.js"); wn.provide("erpnext.stock"); @@ -112,12 +115,6 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ } }, - entries_add: function(doc, cdt, cdn) { - var row = wn.model.get_doc(cdt, cdn); - this.frm.script_manager.copy_from_first_row("mtn_details", row, - ["expense_account", "cost_center"]); - }, - clean_up: function() { // Clear Production Order record from locals, because it is updated via Stock Entry if(this.frm.doc.production_order && @@ -224,6 +221,8 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ mtn_details_add: function(doc, cdt, cdn) { var row = wn.model.get_doc(cdt, cdn); + this.frm.script_manager.copy_from_first_row("mtn_details", row, + ["expense_account", "cost_center"]); if(!row.s_warehouse) row.s_warehouse = this.frm.doc.from_warehouse; if(!row.t_warehouse) row.t_warehouse = this.frm.doc.to_warehouse; @@ -260,24 +259,29 @@ cur_frm.cscript.toggle_related_fields = function(doc) { } } -cur_frm.cscript.delivery_note_no = function(doc,cdt,cdn){ - if(doc.delivery_note_no) return get_server_fields('get_cust_values','','',doc,cdt,cdn,1); +cur_frm.cscript.delivery_note_no = function(doc, cdt, cdn) { + if(doc.delivery_note_no) + return get_server_fields('get_cust_values', '', '', doc, cdt, cdn, 1); } -cur_frm.cscript.sales_invoice_no = function(doc,cdt,cdn){ - if(doc.sales_invoice_no) return get_server_fields('get_cust_values','','',doc,cdt,cdn,1); +cur_frm.cscript.sales_invoice_no = function(doc, cdt, cdn) { + if(doc.sales_invoice_no) + return get_server_fields('get_cust_values', '', '', doc, cdt, cdn, 1); } -cur_frm.cscript.customer = function(doc,cdt,cdn){ - if(doc.customer) return get_server_fields('get_cust_addr','','',doc,cdt,cdn,1); +cur_frm.cscript.customer = function(doc, cdt, cdn) { + if(doc.customer) + return get_server_fields('get_cust_addr', '', '', doc, cdt, cdn, 1); } -cur_frm.cscript.purchase_receipt_no = function(doc,cdt,cdn){ - if(doc.purchase_receipt_no) return get_server_fields('get_supp_values','','',doc,cdt,cdn,1); +cur_frm.cscript.purchase_receipt_no = function(doc, cdt, cdn) { + if(doc.purchase_receipt_no) + return get_server_fields('get_supp_values', '', '', doc, cdt, cdn, 1); } -cur_frm.cscript.supplier = function(doc,cdt,cdn){ - if(doc.supplier) return get_server_fields('get_supp_addr','','',doc,cdt,cdn,1); +cur_frm.cscript.supplier = function(doc, cdt, cdn) { + if(doc.supplier) + return get_server_fields('get_supp_addr', '', '', doc, cdt, cdn, 1); } @@ -314,13 +318,17 @@ cur_frm.fields_dict['mtn_details'].grid.get_field('batch_no').get_query = functi cur_frm.cscript.item_code = function(doc, cdt, cdn) { var d = locals[cdt][cdn]; 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 + '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 }; - return get_server_fields('get_item_details',JSON.stringify(args),'mtn_details',doc,cdt,cdn,1); + return get_server_fields('get_item_details', JSON.stringify(args), + 'mtn_details', doc, cdt, cdn, 1); } cur_frm.cscript.s_warehouse = function(doc, cdt, cdn) { @@ -343,7 +351,8 @@ cur_frm.cscript.uom = function(doc, cdt, cdn) { var d = locals[cdt][cdn]; if(d.uom && d.item_code){ var arg = {'item_code':d.item_code, 'uom':d.uom, 'qty':d.qty} - return get_server_fields('get_uom_details',JSON.stringify(arg),'mtn_details', doc, cdt, cdn, 1); + return get_server_fields('get_uom_details', JSON.stringify(arg), + 'mtn_details', doc, cdt, cdn, 1); } } @@ -354,15 +363,36 @@ cur_frm.cscript.validate = function(doc, cdt, cdn) { } cur_frm.cscript.validate_items = function(doc) { - cl = getchildren('Stock Entry Detail',doc.name,'mtn_details'); + cl = getchildren('Stock Entry Detail', doc.name, 'mtn_details'); if (!cl.length) { alert("Item table can not be blank"); validated = false; } } -cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { - return{ query:"controllers.queries.customer_query" } } +cur_frm.cscript.expense_account = function(doc, cdt, cdn) { + cur_frm.cscript.copy_account_in_all_row(doc, cdt, cdn, "expense_account"); +} -cur_frm.fields_dict.supplier.get_query = function(doc,cdt,cdn) { - return{ query:"controllers.queries.supplier_query" } } +cur_frm.cscript.cost_center = function(doc, cdt, cdn) { + cur_frm.cscript.copy_account_in_all_row(doc, cdt, cdn, "cost_center"); +} + +cur_frm.cscript.copy_account_in_all_row = function(doc, cdt, cdn, fieldname) { + var d = locals[cdt][cdn]; + if(d[fieldname]){ + var cl = getchildren('Stock Entry Detail', doc.name, cur_frm.cscript.fname, doc.doctype); + for(var i = 0; i < cl.length; i++) { + if(!cl[i][fieldname]) cl[i][fieldname] = d[fieldname]; + } + } + refresh_field(cur_frm.cscript.fname); +} + +cur_frm.fields_dict.customer.get_query = function(doc, cdt, cdn) { + return{ query:"controllers.queries.customer_query" } +} + +cur_frm.fields_dict.supplier.get_query = function(doc, cdt, cdn) { + return{ query:"controllers.queries.supplier_query" } +} \ No newline at end of file diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py index 7d8130cc85..735584685a 100644 --- a/stock/doctype/stock_entry/stock_entry.py +++ b/stock/doctype/stock_entry/stock_entry.py @@ -369,7 +369,8 @@ class DocType(StockController): def get_item_details(self, arg): arg = json.loads(arg) - item = sql("""select stock_uom, description, item_name from `tabItem` + item = sql("""select stock_uom, description, item_name, + purchase_account, cost_center from `tabItem` where name = %s and (ifnull(end_of_life,'')='' or end_of_life ='0000-00-00' or end_of_life > now())""", (arg.get('item_code')), as_dict = 1) if not item: @@ -380,6 +381,9 @@ class DocType(StockController): 'stock_uom' : item and item[0]['stock_uom'] or '', 'description' : item and item[0]['description'] or '', 'item_name' : item and item[0]['item_name'] or '', + 'expense_account' : item and item[0]['purchase_account'] or arg["expense_account"] \ + or webnotes.conn.get_value("Company", arg["company"], "default_expense_account"), + 'cost_center' : item and item[0]['cost_center'] or arg["cost_center"], 'qty' : 0, 'transfer_qty' : 0, 'conversion_factor' : 1, From dd6ebc1a4daf2c1f6c2fc5aee2f1c06c65982bcd Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Tue, 15 Oct 2013 15:54:31 +0530 Subject: [PATCH 02/11] [cleanup] comminified copy_account_in_all_row and removed conversion rate from pos setting --- accounts/doctype/sales_invoice/sales_invoice.js | 11 ----------- docs/user/setup/docs.user.setup.price_list.md | 2 +- public/js/controllers/stock_controller.js | 12 ++++++++++++ stock/doctype/stock_entry/stock_entry.js | 11 ----------- stock/doctype/stock_entry/stock_entry.py | 8 ++++---- .../stock_entry_detail/stock_entry_detail.txt | 3 ++- 6 files changed, 19 insertions(+), 28 deletions(-) diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index 4d4f4b7ee0..e980f0a2bc 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -382,17 +382,6 @@ cur_frm.cscript.cost_center = function(doc, cdt, cdn) { cur_frm.cscript.copy_account_in_all_row(doc, cdt, cdn, "cost_center"); } -cur_frm.cscript.copy_account_in_all_row = function(doc, cdt, cdn, fieldname) { - var d = locals[cdt][cdn]; - if(d[fieldname]){ - var cl = getchildren('Sales Invoice Item', doc.name, cur_frm.cscript.fname, doc.doctype); - for(var i = 0; i < cl.length; i++) { - if(!cl[i][fieldname]) cl[i][fieldname] = d[fieldname]; - } - } - refresh_field(cur_frm.cscript.fname); -} - cur_frm.cscript.on_submit = function(doc, cdt, cdn) { if(cint(wn.boot.notification_settings.sales_invoice)) { cur_frm.email_doc(wn.boot.notification_settings.sales_invoice_message); diff --git a/docs/user/setup/docs.user.setup.price_list.md b/docs/user/setup/docs.user.setup.price_list.md index 7214fff514..a1fbf89a1e 100644 --- a/docs/user/setup/docs.user.setup.price_list.md +++ b/docs/user/setup/docs.user.setup.price_list.md @@ -20,7 +20,7 @@ An Item can have multiple prices based on customer, currency, region, shipping c > Setup > Item Price -- Enter Price List and Item Code, Valid for Buying or Selling, Item Name & Item Description will be automatically fetched. +- Enter Price List and Item Code, Valid for Buying or Selling, Item Name and Item Description will be automatically fetched. - Enter Rate and save the document. ![Item-Price](img/item-price.png) diff --git a/public/js/controllers/stock_controller.js b/public/js/controllers/stock_controller.js index e4b03191a1..de18fe0b57 100644 --- a/public/js/controllers/stock_controller.js +++ b/public/js/controllers/stock_controller.js @@ -18,6 +18,7 @@ erpnext.stock.StockController = wn.ui.form.Controller.extend({ } }, + show_general_ledger: function() { var me = this; if(this.frm.doc.docstatus===1 && cint(wn.defaults.get_default("auto_accounting_for_stock"))) { @@ -30,5 +31,16 @@ erpnext.stock.StockController = wn.ui.form.Controller.extend({ wn.set_route("general-ledger"); }); } + }, + + copy_account_in_all_row: function(doc, dt, dn, fieldname) { + var d = locals[dt][dn]; + if(d[fieldname]){ + var cl = getchildren(this.frm.cscript.tname, doc.name, this.frm.cscript.fname, doc.doctype); + for(var i = 0; i < cl.length; i++) { + if(!cl[i][fieldname]) cl[i][fieldname] = d[fieldname]; + } + } + refresh_field(this.frm.cscript.fname); } }); \ No newline at end of file diff --git a/stock/doctype/stock_entry/stock_entry.js b/stock/doctype/stock_entry/stock_entry.js index 26ad62925a..7301bd5b1a 100644 --- a/stock/doctype/stock_entry/stock_entry.js +++ b/stock/doctype/stock_entry/stock_entry.js @@ -378,17 +378,6 @@ cur_frm.cscript.cost_center = function(doc, cdt, cdn) { cur_frm.cscript.copy_account_in_all_row(doc, cdt, cdn, "cost_center"); } -cur_frm.cscript.copy_account_in_all_row = function(doc, cdt, cdn, fieldname) { - var d = locals[cdt][cdn]; - if(d[fieldname]){ - var cl = getchildren('Stock Entry Detail', doc.name, cur_frm.cscript.fname, doc.doctype); - for(var i = 0; i < cl.length; i++) { - if(!cl[i][fieldname]) cl[i][fieldname] = d[fieldname]; - } - } - refresh_field(cur_frm.cscript.fname); -} - cur_frm.fields_dict.customer.get_query = function(doc, cdt, cdn) { return{ query:"controllers.queries.customer_query" } } diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py index 735584685a..9470b221b0 100644 --- a/stock/doctype/stock_entry/stock_entry.py +++ b/stock/doctype/stock_entry/stock_entry.py @@ -368,7 +368,7 @@ class DocType(StockController): def get_item_details(self, arg): arg = json.loads(arg) - + item = sql("""select stock_uom, description, item_name, purchase_account, cost_center from `tabItem` where name = %s and (ifnull(end_of_life,'')='' or end_of_life ='0000-00-00' @@ -381,9 +381,9 @@ class DocType(StockController): 'stock_uom' : item and item[0]['stock_uom'] or '', 'description' : item and item[0]['description'] or '', 'item_name' : item and item[0]['item_name'] or '', - 'expense_account' : item and item[0]['purchase_account'] or arg["expense_account"] \ - or webnotes.conn.get_value("Company", arg["company"], "default_expense_account"), - 'cost_center' : item and item[0]['cost_center'] or arg["cost_center"], + 'expense_account' : item and item[0]['purchase_account'] or arg.get("expense_account") \ + or webnotes.conn.get_value("Company", arg.get("company"), "default_expense_account"), + 'cost_center' : item and item[0]['cost_center'] or arg.get("cost_center"), 'qty' : 0, 'transfer_qty' : 0, 'conversion_factor' : 1, diff --git a/stock/doctype/stock_entry_detail/stock_entry_detail.txt b/stock/doctype/stock_entry_detail/stock_entry_detail.txt index b400cdd248..b766250670 100644 --- a/stock/doctype/stock_entry_detail/stock_entry_detail.txt +++ b/stock/doctype/stock_entry_detail/stock_entry_detail.txt @@ -2,7 +2,7 @@ { "creation": "2013-03-29 18:22:12", "docstatus": 0, - "modified": "2013-08-28 19:25:38", + "modified": "2013-10-15 14:58:09", "modified_by": "Administrator", "owner": "Administrator" }, @@ -154,6 +154,7 @@ "print_hide": 1 }, { + "default": ":Company", "depends_on": "eval:sys_defaults.auto_accounting_for_stock", "doctype": "DocField", "fieldname": "cost_center", From b338b6ed24fb6dff3e23139eb8f4ec1153e88b2b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 15 Oct 2013 16:55:24 +0530 Subject: [PATCH 03/11] [fix] [minor] validate converion rate --- accounts/doctype/sales_invoice/sales_invoice.py | 1 - public/js/transaction.js | 3 +-- selling/doctype/quotation/quotation.py | 2 -- selling/doctype/sales_common/sales_common.py | 15 --------------- selling/doctype/sales_order/sales_order.py | 2 +- stock/doctype/delivery_note/delivery_note.py | 2 +- 6 files changed, 3 insertions(+), 22 deletions(-) diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index daf01ab801..3ae74e481e 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -52,7 +52,6 @@ class DocType(SellingController): sales_com_obj = get_obj('Sales Common') sales_com_obj.check_stop_sales_order(self) sales_com_obj.check_active_sales_items(self) - sales_com_obj.check_conversion_rate(self) sales_com_obj.validate_max_discount(self, 'entries') self.validate_customer_account() self.validate_debit_acc() diff --git a/public/js/transaction.js b/public/js/transaction.js index 79ea53623f..3cb40514a8 100644 --- a/public/js/transaction.js +++ b/public/js/transaction.js @@ -173,8 +173,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ this.frm.doc.plc_conversion_rate !== this.frm.doc.conversion_rate) { this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate); } - - this.calculate_taxes_and_totals(); + if(flt(this.frm.doc.conversion_rate)>0.0) this.calculate_taxes_and_totals(); }, get_price_list_currency: function(buying_or_selling) { diff --git a/selling/doctype/quotation/quotation.py b/selling/doctype/quotation/quotation.py index 8eb3654e62..8209548fcb 100644 --- a/selling/doctype/quotation/quotation.py +++ b/selling/doctype/quotation/quotation.py @@ -111,8 +111,6 @@ class DocType(SellingController): sales_com_obj = get_obj('Sales Common') sales_com_obj.check_active_sales_items(self) sales_com_obj.validate_max_discount(self,'quotation_details') - sales_com_obj.check_conversion_rate(self) - def on_update(self): # Set Quotation Status diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py index 8271c82874..ad626da460 100644 --- a/selling/doctype/sales_common/sales_common.py +++ b/selling/doctype/sales_common/sales_common.py @@ -74,21 +74,6 @@ class DocType(TransactionBase): msgprint("You cannot give more than " + cstr(discount[0]['max_discount']) + " % discount on Item Code : "+cstr(d.item_code)) raise Exception - # Check Conversion Rate (i.e. it will not allow conversion rate to be 1 for Currency other than default currency set in Global Defaults) - # =========================================================================== - def check_conversion_rate(self, obj): - default_currency = get_company_currency(obj.doc.company) - if not default_currency: - msgprint('Message: Please enter default currency in Company Master') - raise Exception - if (obj.doc.currency == default_currency and flt(obj.doc.conversion_rate) != 1.00) or not obj.doc.conversion_rate or (obj.doc.currency != default_currency and flt(obj.doc.conversion_rate) == 1.00): - msgprint("Please Enter Appropriate Conversion Rate for Customer's Currency to Base Currency (%s --> %s)" % (obj.doc.currency, default_currency), raise_exception = 1) - - if (obj.doc.price_list_currency == default_currency and flt(obj.doc.plc_conversion_rate) != 1.00) or not obj.doc.plc_conversion_rate or (obj.doc.price_list_currency != default_currency and flt(obj.doc.plc_conversion_rate) == 1.00): - msgprint("Please Enter Appropriate Conversion Rate for Price List Currency to Base Currency (%s --> %s)" % (obj.doc.price_list_currency, default_currency), raise_exception = 1) - - - # Get Tax rate if account type is TAX # ========================================================================= def get_rate(self, arg): diff --git a/selling/doctype/sales_order/sales_order.py b/selling/doctype/sales_order/sales_order.py index 435a9768aa..66b487e450 100644 --- a/selling/doctype/sales_order/sales_order.py +++ b/selling/doctype/sales_order/sales_order.py @@ -130,7 +130,7 @@ class DocType(SellingController): self.validate_warehouse() sales_com_obj = get_obj(dt = 'Sales Common') sales_com_obj.check_active_sales_items(self) - sales_com_obj.check_conversion_rate(self) + sales_com_obj.validate_max_discount(self,'sales_order_details') self.doclist = sales_com_obj.make_packing_list(self,'sales_order_details') diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py index 2d1a3bece6..eb2b204d0c 100644 --- a/stock/doctype/delivery_note/delivery_note.py +++ b/stock/doctype/delivery_note/delivery_note.py @@ -95,7 +95,7 @@ class DocType(SellingController): self.validate_uom_is_integer("stock_uom", "qty") sales_com_obj.validate_max_discount(self, 'delivery_note_details') - sales_com_obj.check_conversion_rate(self) + # Set actual qty for each item in selected warehouse self.update_current_stock() From 61b5c59e701b383250b45c770dc3fd6fcf78a549 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Tue, 15 Oct 2013 20:24:34 +0530 Subject: [PATCH 04/11] [fix] fixed conversion rate for mapping any documents --- accounts/doctype/sales_invoice/sales_invoice.js | 2 +- controllers/accounts_controller.py | 6 +++--- controllers/buying_controller.py | 2 +- controllers/selling_controller.py | 6 +++--- docs/user/stock/docs.user.stock.item.md | 4 ++-- public/js/transaction.js | 14 ++++++++------ 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index e980f0a2bc..8192fe5c52 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -29,7 +29,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte // toggle to pos view if is_pos is 1 in user_defaults if ((cint(wn.defaults.get_user_defaults("is_pos"))===1 || cur_frm.doc.is_pos) && cint(wn.defaults.get_user_defaults("fs_pos_view"))===1) { - if(this.frm.doc.__islocal && !this.frm.doc.amended_from) { + if(this.frm.doc.__islocal && !this.frm.doc.amended_from && !this.frm.doc.customer) { this.frm.set_value("is_pos", 1); this.is_pos(function() {cur_frm.cscript.toggle_pos(true);}); } diff --git a/controllers/accounts_controller.py b/controllers/accounts_controller.py index 3af9c7a547..2b6a21f5ed 100644 --- a/controllers/accounts_controller.py +++ b/controllers/accounts_controller.py @@ -52,7 +52,7 @@ class AccountsController(TransactionBase): msgprint(_("Account for this ") + fieldname + _(" has been freezed. ") + self.doc.doctype + _(" can not be made."), raise_exception=1) - def set_price_list_currency(self, buying_or_selling, for_validate=False): + def set_price_list_currency(self, buying_or_selling): if self.meta.get_field("currency"): company_currency = get_company_currency(self.doc.company) @@ -66,7 +66,7 @@ class AccountsController(TransactionBase): if self.doc.price_list_currency == company_currency: self.doc.plc_conversion_rate = 1.0 - elif not self.doc.plc_conversion_rate or not for_validate: + elif not self.doc.plc_conversion_rate: self.doc.plc_conversion_rate = self.get_exchange_rate( self.doc.price_list_currency, company_currency) @@ -76,7 +76,7 @@ class AccountsController(TransactionBase): self.doc.conversion_rate = self.doc.plc_conversion_rate elif self.doc.currency == company_currency: self.doc.conversion_rate = 1.0 - elif not self.doc.conversion_rate or not for_validate: + elif not self.doc.conversion_rate: self.doc.conversion_rate = self.get_exchange_rate(self.doc.currency, company_currency) diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py index 2aa7c834da..fd3428e6ad 100644 --- a/controllers/buying_controller.py +++ b/controllers/buying_controller.py @@ -28,7 +28,7 @@ class BuyingController(StockController): super(BuyingController, self).set_missing_values(for_validate) self.set_supplier_from_item_default() - self.set_price_list_currency("Buying", for_validate) + self.set_price_list_currency("Buying") # set contact and address details for supplier, if they are not mentioned if self.doc.supplier and not (self.doc.contact_person and self.doc.supplier_address): diff --git a/controllers/selling_controller.py b/controllers/selling_controller.py index 845ba859e0..37674ee4bf 100644 --- a/controllers/selling_controller.py +++ b/controllers/selling_controller.py @@ -20,7 +20,7 @@ class SellingController(StockController): # set contact and address details for customer, if they are not mentioned self.set_missing_lead_customer_details() - self.set_price_list_and_item_details(for_validate) + self.set_price_list_and_item_details() if self.doc.fields.get("__islocal"): self.set_taxes("other_charges", "charge") @@ -38,8 +38,8 @@ class SellingController(StockController): if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname): self.doc.fields[fieldname] = val - def set_price_list_and_item_details(self, for_validate=False): - self.set_price_list_currency("Selling", for_validate) + def set_price_list_and_item_details(self): + self.set_price_list_currency("Selling") self.set_missing_item_details(get_item_details) def get_other_charges(self): diff --git a/docs/user/stock/docs.user.stock.item.md b/docs/user/stock/docs.user.stock.item.md index f7746c4842..fdf304559b 100644 --- a/docs/user/stock/docs.user.stock.item.md +++ b/docs/user/stock/docs.user.stock.item.md @@ -38,11 +38,11 @@ In ERPNext, you can select different type of Warehouses to stock your different ### Serialized and Batched Inventory -These numbers help to track individual units or batches of Items which you sell. It also tracks warranty and returns. In case any individual Item is recalled by the supplier the number system helps to track individual Item. The numbering system also manages expiry dates. Please note that if you sell your items in thousands, and if the items are very small like pens or erasers, you need not serialize them. In ERPNext, you will have to mention the serial number in some accounting entries. To create serial numbers you will have to manually create all the numbers in your entries. If your product is not a big consumer durable Item, if it has no warranty and has no chances of being recalled, avoid giving serial numbers. +These numbers help to track individual units or batches of Items which you sell. It also tracks warranty and returns. In case any individual Item is recalled by the supplier the number system helps to track individual Item. The numbering system also manages expiry dates. Please note that if you sell your items in thousands, and if the items are very small like pens or erasers, you need not serialize them. In ERPNext, you will have to mention the serial number in some accounting entries. To create serial numbers you will have to manually create all the numbers in your entries. If your product is not a big consumer durable Item, if it has no warranty and has no chances of being recalled, avoid giving serial numbers. > Important: Once you mark an item as serialized or batched or neither, you cannot change it after you have made any stock entry. -- [Disucssion on Serialized Inventory](docs.user.stock.serialized.html) +- [Discussion on Serialized Inventory](docs.user.stock.serialized.html) ### Re Ordering diff --git a/public/js/transaction.js b/public/js/transaction.js index 79ea53623f..e32fe1533e 100644 --- a/public/js/transaction.js +++ b/public/js/transaction.js @@ -24,9 +24,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ }, function(fieldname, value) { if(me.frm.fields_dict[fieldname] && !me.frm.doc[fieldname]) me.frm.set_value(fieldname, value); - }); - - me.frm.script_manager.trigger("company"); + }); } if(this.other_fname) { @@ -39,9 +37,9 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ }, onload_post_render: function() { - if(this.frm.doc.__islocal && this.frm.doc.company && - !this.frm.doc.customer && !this.frm.doc.is_pos) { - var me = this; + var me = this; + if(this.frm.doc.__islocal && this.frm.doc.company && !this.frm.doc.is_pos) { + if(!this.frm.doc.customer) { return this.frm.call({ doc: this.frm.doc, method: "onload_post_render", @@ -50,8 +48,12 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ // remove this call when using client side mapper me.set_default_values(); me.set_dynamic_labels(); + me.calculate_taxes_and_totals() } }); + } else { + this.calculate_taxes_and_totals(); + } } }, From fc75d96abd69fc2620c0f61137b6ab8ae46ee8d9 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 16 Oct 2013 11:48:15 +0530 Subject: [PATCH 05/11] [fix] [minor] Purchase Invoice - Amount for Stock received but not billed --- accounts/doctype/purchase_invoice/purchase_invoice.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index 3c3bcb7022..58101da2ad 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -367,9 +367,8 @@ class DocType(BuyingController): # expense will be booked in sales invoice stock_item_and_auto_accounting_for_stock = True - valuation_amt = (flt(item.amount, self.precision("amount", item)) + - flt(item.item_tax_amount, self.precision("item_tax_amount", item)) + - flt(item.rm_supp_cost, self.precision("rm_supp_cost", item))) + valuation_amt = flt(item.valuation_rate) * flt(item.qty) * \ + flt(item.conversion_factor) gl_entries.append( self.get_gl_dict({ From 185991d54796a41e13527ef59418102af2e7a417 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 16 Oct 2013 13:08:53 +0530 Subject: [PATCH 06/11] [fix] [minor] rounding error in purchase invoice gl entry --- .../doctype/purchase_invoice/purchase_invoice.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index 58101da2ad..c1e92b9f4f 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -359,6 +359,7 @@ class DocType(BuyingController): # item gl entries stock_item_and_auto_accounting_for_stock = False stock_items = self.get_stock_items() + rounding_diff = 0.0 for item in self.doclist.get({"parentfield": "entries"}): if auto_accounting_for_stock and item.item_code in stock_items: if flt(item.valuation_rate): @@ -367,8 +368,13 @@ class DocType(BuyingController): # expense will be booked in sales invoice stock_item_and_auto_accounting_for_stock = True - valuation_amt = flt(item.valuation_rate) * flt(item.qty) * \ - flt(item.conversion_factor) + valuation_amt = flt(flt(item.valuation_rate) * flt(item.qty) * \ + flt(item.conversion_factor), self.precision("valuation_rate", item)) + + rounding_diff += (flt(item.amount, self.precision("amount", item)) + + flt(item.item_tax_amount, self.precision("item_tax_amount", item)) + + flt(item.rm_supp_cost, self.precision("rm_supp_cost", item)) - + valuation_amt) gl_entries.append( self.get_gl_dict({ @@ -397,6 +403,12 @@ class DocType(BuyingController): expenses_included_in_valuation = \ self.get_company_default("expenses_included_in_valuation") + if rounding_diff: + import operator + cost_center_with_max_value = max(valuation_tax.iteritems(), + key=operator.itemgetter(1))[0] + valuation_tax[cost_center_with_max_value] -= flt(rounding_diff) + for cost_center, amount in valuation_tax.items(): gl_entries.append( self.get_gl_dict({ From ccbde214c2845fbbcebcf015870bc1ca8b16f0fb Mon Sep 17 00:00:00 2001 From: Maxwell Date: Wed, 16 Oct 2013 16:52:01 -0300 Subject: [PATCH 07/11] Fix UnicodeDecodeError ```python Traceback (most recent call last): File "install_erpnext.py", line 348, in install() File "install_erpnext.py", line 13, in install install_pre_requisites() File "install_erpnext.py", line 25, in install_pre_requisites install_using_yum() File "install_erpnext.py", line 90, in install_using_yum update_config_for_redhat() File "install_erpnext.py", line 106, in update_config_for_redhat exec_in_shell("chkconfig --level 2345 %s on" % service) File "install_erpnext.py", line 339, in exec_in_shell if err and any((kw in err.lower() for kw in ["traceback", "error", "exception"])): File "install_erpnext.py", line 339, in if err and any((kw in err.lower() for kw in ["traceback", "error", "exception"])): ``` --- install_erpnext.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/install_erpnext.py b/install_erpnext.py index 79f79d7cc0..7f3b8c3b65 100644 --- a/install_erpnext.py +++ b/install_erpnext.py @@ -332,9 +332,11 @@ def exec_in_shell(cmd): stdout.seek(0) out = stdout.read() + if out: out = out.decode('utf-8') stderr.seek(0) err = stderr.read() + if err: err = err.decode('utf-8') if err and any((kw in err.lower() for kw in ["traceback", "error", "exception"])): print out @@ -345,4 +347,4 @@ def exec_in_shell(cmd): return out if __name__ == "__main__": - install() \ No newline at end of file + install() From 564c621c3ecadf452689ba2ab909250dfdcd1457 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Thu, 17 Oct 2013 11:31:11 +0530 Subject: [PATCH 08/11] [fix] [minor] conversion rate fix --- public/js/transaction.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/js/transaction.js b/public/js/transaction.js index e32fe1533e..4ff583016c 100644 --- a/public/js/transaction.js +++ b/public/js/transaction.js @@ -26,7 +26,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ me.frm.set_value(fieldname, value); }); } - + if(this.other_fname) { this[this.other_fname + "_remove"] = this.calculate_taxes_and_totals; } @@ -46,6 +46,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ freeze: true, callback: function(r) { // remove this call when using client side mapper + me.frm.script_manager.trigger("company"); me.set_default_values(); me.set_dynamic_labels(); me.calculate_taxes_and_totals() @@ -226,7 +227,8 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ plc_conversion_rate: function() { if(this.frm.doc.price_list_currency === this.get_company_currency()) { this.frm.set_value("plc_conversion_rate", 1.0); - } else if(this.frm.doc.price_list_currency === this.frm.doc.currency) { + } + if(this.frm.doc.price_list_currency === this.frm.doc.currency) { this.frm.set_value("conversion_rate", this.frm.doc.plc_conversion_rate); this.calculate_taxes_and_totals(); } From 3add576b1ea54e18f3d76f618cab0d131f025b8e Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Thu, 17 Oct 2013 11:32:44 +0530 Subject: [PATCH 09/11] [fix] [minor] conversion rate fix --- public/js/transaction.js | 1 - 1 file changed, 1 deletion(-) diff --git a/public/js/transaction.js b/public/js/transaction.js index 4ff583016c..c1b83702d6 100644 --- a/public/js/transaction.js +++ b/public/js/transaction.js @@ -46,7 +46,6 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ freeze: true, callback: function(r) { // remove this call when using client side mapper - me.frm.script_manager.trigger("company"); me.set_default_values(); me.set_dynamic_labels(); me.calculate_taxes_and_totals() From acf65a72255c823409840c2cb76c821902f04764 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Thu, 17 Oct 2013 13:04:26 +0530 Subject: [PATCH 10/11] [fix] [minor] conversion rate related fixes --- .../doctype/sales_invoice/sales_invoice.js | 28 +++++++++++-------- public/js/transaction.js | 5 ++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index 8192fe5c52..b5c1646176 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -18,21 +18,21 @@ wn.provide("erpnext.accounts"); erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.extend({ onload: function() { this._super(); - - if(!this.frm.doc.__islocal) { + + if(!this.frm.doc.__islocal && !this.frm.doc.customer && this.frm.doc.debit_to) { // show debit_to in print format - if(!this.frm.doc.customer && this.frm.doc.debit_to) { - this.frm.set_df_property("debit_to", "print_hide", 0); - } + this.frm.set_df_property("debit_to", "print_hide", 0); } // toggle to pos view if is_pos is 1 in user_defaults - if ((cint(wn.defaults.get_user_defaults("is_pos"))===1 || cur_frm.doc.is_pos) && - cint(wn.defaults.get_user_defaults("fs_pos_view"))===1) { - if(this.frm.doc.__islocal && !this.frm.doc.amended_from && !this.frm.doc.customer) { - this.frm.set_value("is_pos", 1); - this.is_pos(function() {cur_frm.cscript.toggle_pos(true);}); - } + if ((cint(wn.defaults.get_user_defaults("is_pos"))===1 || cur_frm.doc.is_pos)) { + if(this.frm.doc.__islocal && !this.frm.doc.amended_from && !this.frm.doc.customer) { + this.frm.set_value("is_pos", 1); + this.is_pos(function() { + if (cint(wn.defaults.get_user_defaults("fs_pos_view"))===1) + cur_frm.cscript.toggle_pos(true); + }); + } } // if document is POS then change default print format to "POS Invoice" @@ -44,7 +44,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte refresh: function(doc, dt, dn) { this._super(); - + cur_frm.cscript.is_opening(doc, dt, dn); cur_frm.dashboard.reset(); @@ -141,6 +141,10 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte callback: function(r) { if(!r.exc) { me.frm.script_manager.trigger("update_stock"); + me.set_default_values(); + me.set_dynamic_labels(); + me.calculate_taxes_and_totals(); + if(callback_fn) callback_fn() } } diff --git a/public/js/transaction.js b/public/js/transaction.js index c1b83702d6..6b777204e7 100644 --- a/public/js/transaction.js +++ b/public/js/transaction.js @@ -48,7 +48,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ // remove this call when using client side mapper me.set_default_values(); me.set_dynamic_labels(); - me.calculate_taxes_and_totals() + me.calculate_taxes_and_totals(); } }); } else { @@ -171,7 +171,8 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ conversion_rate: function() { if(this.frm.doc.currency === this.get_company_currency()) { this.frm.set_value("conversion_rate", 1.0); - } else if(this.frm.doc.currency === this.frm.doc.price_list_currency && + } + if(this.frm.doc.currency === this.frm.doc.price_list_currency && this.frm.doc.plc_conversion_rate !== this.frm.doc.conversion_rate) { this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate); } From 04638a5f77af24480df21c9051615b3c41860b4a Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Thu, 17 Oct 2013 13:19:46 +0530 Subject: [PATCH 11/11] [fix] [minor] onload post render also check for supplier --- public/js/transaction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/transaction.js b/public/js/transaction.js index 6b777204e7..e948829af9 100644 --- a/public/js/transaction.js +++ b/public/js/transaction.js @@ -39,7 +39,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ onload_post_render: function() { var me = this; if(this.frm.doc.__islocal && this.frm.doc.company && !this.frm.doc.is_pos) { - if(!this.frm.doc.customer) { + if(!this.frm.doc.customer || !this.frm.doc.supplier) { return this.frm.call({ doc: this.frm.doc, method: "onload_post_render",