minor fixes
diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js
index dae1e7a..937e60d 100644
--- a/erpnext/buying/doctype/purchase_common/purchase_common.js
+++ b/erpnext/buying/doctype/purchase_common/purchase_common.js
@@ -73,43 +73,6 @@
this.supplier_address();
},
- item_code: function(doc, cdt, cdn) {
- var me = this;
- var item = wn.model.get_doc(cdt, cdn);
- if(item.item_code) {
- if(!this.validate_company_and_party("supplier")) {
- cur_frm.fields_dict[me.frm.cscript.fname].grid.grid_rows[item.idx - 1].remove();
- } else {
- return this.frm.call({
- method: "erpnext.stock.get_item_details.get_item_details",
- child: item,
- args: {
- args: {
- item_code: item.item_code,
- warehouse: item.warehouse,
- doctype: me.frm.doc.doctype,
- docname: me.frm.doc.name,
- supplier: me.frm.doc.supplier,
- conversion_rate: me.frm.doc.conversion_rate,
- buying_price_list: me.frm.doc.buying_price_list,
- price_list_currency: me.frm.doc.price_list_currency,
- plc_conversion_rate: me.frm.doc.plc_conversion_rate,
- is_subcontracted: me.frm.doc.is_subcontracted,
- company: me.frm.doc.company,
- currency: me.frm.doc.currency,
- transaction_date: me.frm.doc.transaction_date
- }
- },
- callback: function(r) {
- if(!r.exc) {
- me.frm.script_manager.trigger("price_list_rate", cdt, cdn);
- }
- }
- });
- }
- }
- },
-
buying_price_list: function() {
this.get_price_list_currency("Buying");
},
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index c9000b5..2bc3852 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -90,7 +90,6 @@
for item in self.doclist.get({"parentfield": self.fname}):
if item.fields.get("item_code"):
args = item.fields.copy().update(self.doc.fields)
- args.price_list = args.selling_price_list or args.buying_price_list
ret = get_item_details(args)
for fieldname, value in ret.items():
if self.meta.get_field(fieldname, parentfield=self.fname) and \
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index 5ac78bf..47eacf2 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -416,7 +416,7 @@
item.stock_uom,
item.default_warehouse,
item.expense_account as expense_account,
- item.buying_cost_center
+ item.buying_cost_center as cost_center
from
`tab%(table)s` bom_item, `tabItem` item
where
diff --git a/erpnext/patches/4_0/fields_to_be_renamed.py b/erpnext/patches/4_0/fields_to_be_renamed.py
index 91a1aa4..6bacd19 100644
--- a/erpnext/patches/4_0/fields_to_be_renamed.py
+++ b/erpnext/patches/4_0/fields_to_be_renamed.py
@@ -108,16 +108,22 @@
def reload_docs(docs):
for dn in docs:
- module = webnotes.conn.get_value("DocType", dn, "module").lower().replace(" ", "_")
- webnotes.reload_doc(module, "doctype", dn.lower().replace(" ", "_"))
+ webnotes.reload_doc(get_module(dn), "doctype", dn.lower().replace(" ", "_"))
# reload all standard print formats
for pf in webnotes.conn.sql("""select name, module from `tabPrint Format`
where ifnull(standard, 'No') = 'Yes'""", as_dict=1):
- webnotes.reload_doc(pf.module, "Print Format", pf.name)
+ try:
+ webnotes.reload_doc(pf.module, "Print Format", pf.name)
+ except Exception, e:
+ print e
+ pass
# reload all standard reports
- for r in webnotes.conn.sql("""select name, module from `tabReport`
+ for r in webnotes.conn.sql("""select name, ref_doctype from `tabReport`
where ifnull(is_standard, 'No') = 'Yes'
and report_type in ('Report Builder', 'Query Report')""", as_dict=1):
- webnotes.reload_doc(r.module, "Report", r.name)
\ No newline at end of file
+ webnotes.reload_doc(get_module(r.ref_doctype), "Report", r.name)
+
+def get_module(dn):
+ return webnotes.conn.get_value("DocType", dn, "module").lower().replace(" ", "_")
\ No newline at end of file
diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js
index 6d570e4..d77819f 100644
--- a/erpnext/public/js/transaction.js
+++ b/erpnext/public/js/transaction.js
@@ -110,6 +110,50 @@
this.frm.refresh();
}
},
+
+
+ item_code: function(doc, cdt, cdn) {
+ var me = this;
+ var item = wn.model.get_doc(cdt, cdn);
+ if(item.item_code || item.barcode || item.serial_no) {
+ if(!this.validate_company_and_party()) {
+ cur_frm.fields_dict[me.frm.cscript.fname].grid.grid_rows[item.idx - 1].remove();
+ } else {
+ return this.frm.call({
+ method: "erpnext.stock.get_item_details.get_item_details",
+ child: item,
+ args: {
+ args: {
+ item_code: item.item_code,
+ barcode: item.barcode,
+ serial_no: item.serial_no,
+ warehouse: item.warehouse,
+ doctype: me.frm.doc.doctype,
+ docname: me.frm.doc.name,
+ customer: me.frm.doc.customer,
+ supplier: me.frm.doc.supplier,
+ currency: me.frm.doc.currency,
+ conversion_rate: me.frm.doc.conversion_rate,
+ price_list: me.frm.doc.selling_price_list ||
+ me.frm.doc.buying_price_list,
+ price_list_currency: me.frm.doc.price_list_currency,
+ plc_conversion_rate: me.frm.doc.plc_conversion_rate,
+ company: me.frm.doc.company,
+ order_type: me.frm.doc.order_type,
+ is_pos: cint(me.frm.doc.is_pos),
+ is_subcontracted: me.frm.doc.is_subcontracted,
+ transaction_date: me.frm.doc.transaction_date
+ }
+ },
+ callback: function(r) {
+ if(!r.exc) {
+ me.frm.script_manager.trigger("price_list_rate", cdt, cdn);
+ }
+ }
+ });
+ }
+ }
+ },
serial_no: function(doc, cdt, cdn) {
var me = this;
@@ -455,25 +499,18 @@
</table></div>';
},
- _validate_before_fetch: function(fieldname) {
- var me = this;
- if(!me.frm.doc[fieldname]) {
- return (wn._("Please specify") + ": " +
- wn.meta.get_label(me.frm.doc.doctype, fieldname, me.frm.doc.name) +
- ". " + wn._("It is needed to fetch Item Details."));
- }
- return null;
- },
-
- validate_company_and_party: function(party_field) {
+ validate_company_and_party: function() {
var me = this;
var valid = true;
- var msg = "";
- $.each(["company", party_field], function(i, fieldname) {
- var msg_for_fieldname = me._validate_before_fetch(fieldname);
- if(msg_for_fieldname) {
- msgprint(msg_for_fieldname);
- valid = false;
+
+ $.each(["company", "customer", "supplier"], function(i, fieldname) {
+ if(wn.meta.has_field(me.frm.doc.doctype, fieldname)) {
+ if (!me.frm.doc[fieldname]) {
+ msgprint(wn._("Please specify") + ": " +
+ wn.meta.get_label(me.frm.doc.doctype, fieldname, me.frm.doc.name) +
+ ". " + wn._("It is needed to fetch Item Details."));
+ valid = false;
+ }
}
});
return valid;
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index b1f4394..e04a68e 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -91,8 +91,8 @@
validate_company_and_party: function(party_field) {
if(!this.frm.doc.quotation_to) {
- msgprint(wn._("Please select a value for" + " " + wn.meta.get_label(this.frm.doc.doctype,
- "quotation_to", this.frm.doc.name)));
+ msgprint(wn._("Please select a value for" + " " +
+ wn.meta.get_label(this.frm.doc.doctype, "quotation_to", this.frm.doc.name)));
return false;
} else if (this.frm.doc.quotation_to == "Lead") {
return true;
diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js
index cf2347f..0f7bc67 100644
--- a/erpnext/selling/sales_common.js
+++ b/erpnext/selling/sales_common.js
@@ -119,46 +119,6 @@
this.item_code(doc, cdt, cdn);
},
- item_code: function(doc, cdt, cdn) {
- var me = this;
- var item = wn.model.get_doc(cdt, cdn);
- if(item.item_code || item.barcode || item.serial_no) {
- if(!this.validate_company_and_party("customer")) {
- cur_frm.fields_dict[me.frm.cscript.fname].grid.grid_rows[item.idx - 1].remove();
- } else {
- return this.frm.call({
- method: "erpnext.stock.get_item_details.get_item_details",
- child: item,
- args: {
- args: {
- item_code: item.item_code,
- barcode: item.barcode,
- serial_no: item.serial_no,
- warehouse: item.warehouse,
- doctype: me.frm.doc.doctype,
- parentfield: item.parentfield,
- customer: me.frm.doc.customer,
- currency: me.frm.doc.currency,
- conversion_rate: me.frm.doc.conversion_rate,
- price_list: me.frm.doc.selling_price_list,
- price_list_currency: me.frm.doc.price_list_currency,
- plc_conversion_rate: me.frm.doc.plc_conversion_rate,
- company: me.frm.doc.company,
- order_type: me.frm.doc.order_type,
- is_pos: cint(me.frm.doc.is_pos),
- "transaction_type": "selling"
- }
- },
- callback: function(r) {
- if(!r.exc) {
- me.frm.script_manager.trigger("price_list_rate", cdt, cdn);
- }
- }
- });
- }
- }
- },
-
selling_price_list: function() {
this.get_price_list_currency("Selling");
},
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index c9f7444..608f1ba 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -578,7 +578,7 @@
se_child.stock_uom = item_dict[d]["stock_uom"]
se_child.qty = flt(item_dict[d]["qty"])
se_child.expense_account = item_dict[d]["expense_account"] or expense_account
- se_child.cost_center = item_dict[d]["buying_cost_center"] or cost_center
+ se_child.cost_center = item_dict[d]["cost_center"] or cost_center
# in stock uom
se_child.transfer_qty = flt(item_dict[d]["qty"])
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 3d199ca..6f9cd4f 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -35,6 +35,9 @@
if not args.get("transaction_type"):
args.transaction_type = "selling" if args.get("customer") else "buying"
+
+ if not args.get("price_list"):
+ args.price_list = args.get("selling_price_list") or args.get("buying_price_list")
if args.barcode:
args.item_code = get_item_code(barcode=args.barcode)
@@ -54,32 +57,23 @@
out.update(get_available_qty(args.item_code, out.warehouse))
out.update(get_projected_qty(item.name, out.warehouse))
- if args.transaction_date and item.lead_time_days:
- out.schedule_date = out.lead_time_date = add_days(args.transaction_date,
- item.lead_time_days)
-
get_price_list_rate(args, item_bean, out)
- # out.update(_get_item_discount(out.item_group, args.customer))
+ out.update(get_item_discount(out.item_group, args.customer))
if args.transaction_type == "selling" and cint(args.is_pos):
out.update(get_pos_settings_item_details(args.company, args))
- if args.doctype in ("Sales Invoice", "Delivery Note"):
+ if args.get("doctype") in ("Sales Invoice", "Delivery Note"):
if item_bean.doc.has_serial_no == "Yes" and not args.serial_no:
out.serial_no = get_serial_nos_by_fifo(args, item_bean)
+
+ if args.transaction_date and item.lead_time_days:
+ out.schedule_date = out.lead_time_date = add_days(args.transaction_date,
+ item.lead_time_days)
return out
-def get_serial_nos_by_fifo(args, item_bean):
- return "\n".join(webnotes.conn.sql_list("""select name from `tabSerial No`
- where item_code=%(item_code)s and warehouse=%(warehouse)s and status='Available'
- order by timestamp(purchase_date, purchase_time) asc limit %(qty)s""", {
- "item_code": args.item_code,
- "warehouse": args.warehouse,
- "qty": cint(args.qty)
- }))
-
def get_item_code(barcode=None, serial_no=None):
if barcode:
item_code = webnotes.conn.get_value("Item", {"barcode": barcode})
@@ -101,7 +95,7 @@
if args.transaction_type == "selling":
# validate if sales item or service item
- if args.order_type == "Maintenance":
+ if args.get("order_type") == "Maintenance":
if item.is_service_item != "Yes":
throw(_("Item") + (" %s: " % item.name) +
_("not a service item.") +
@@ -115,7 +109,7 @@
if item.is_purchase_item != "Yes":
throw(_("Item") + (" %s: " % item.name) + _("not a purchase item"))
- if args.is_subcontracted == "Yes" and item.is_sub_contracted_item != "Yes":
+ if args.get("is_subcontracted") == "Yes" and item.is_sub_contracted_item != "Yes":
throw(_("Item") + (" %s: " % item.name) +
_("not a sub-contracted item.") +
_("Please select a sub-contracted item or do not sub-contract the transaction."))
@@ -129,31 +123,31 @@
if len(user_default_warehouse_list)==1 else ""
out = webnotes._dict({
- "item_code": item.name,
- "item_name": item.item_name,
- "description": item.description_html or item.description,
- "warehouse": user_default_warehouse or args.warehouse or item.default_warehouse,
- "income_account": item.default_income_account or args.income_account \
- or webnotes.conn.get_value("Company", args.company, "default_income_account"),
- "expense_account": item.expense_account or args.expense_account \
- or webnotes.conn.get_value("Company", args.company, "default_expense_account"),
- "cost_center": item.selling_cost_center \
- if args.transaction_type == "selling" else args.buying_cost_center,
- "batch_no": None,
- "item_tax_rate": json.dumps(dict(([d.tax_type, d.tax_rate] for d in
- item_bean.doclist.get({"parentfield": "item_tax"})))),
- "uom": item.stock_uom,
- "min_order_qty": flt(item.min_order_qty) if args.doctype == "Material Request" else "",
- "conversion_factor": 1.0,
- "qty": 1.0,
- "price_list_rate": 0.0,
- "base_price_list_rate": 0.0,
- "rate": 0.0,
- "base_rate": 0.0,
- "amount": 0.0,
- "base_amount": 0.0,
- "discount_percentage": 0.0
- })
+ "item_code": item.name,
+ "item_name": item.item_name,
+ "description": item.description_html or item.description,
+ "warehouse": user_default_warehouse or args.warehouse or item.default_warehouse,
+ "income_account": item.default_income_account or args.income_account \
+ or webnotes.conn.get_value("Company", args.company, "default_income_account"),
+ "expense_account": item.expense_account or args.expense_account \
+ or webnotes.conn.get_value("Company", args.company, "default_expense_account"),
+ "cost_center": item.selling_cost_center \
+ if args.transaction_type == "selling" else args.buying_cost_center,
+ "batch_no": None,
+ "item_tax_rate": json.dumps(dict(([d.tax_type, d.tax_rate] for d in
+ item_bean.doclist.get({"parentfield": "item_tax"})))),
+ "uom": item.stock_uom,
+ "min_order_qty": flt(item.min_order_qty) if args.doctype == "Material Request" else "",
+ "conversion_factor": 1.0,
+ "qty": 1.0,
+ "price_list_rate": 0.0,
+ "base_price_list_rate": 0.0,
+ "rate": 0.0,
+ "base_rate": 0.0,
+ "amount": 0.0,
+ "base_amount": 0.0,
+ "discount_percentage": 0.0
+ })
for fieldname in ("item_name", "item_group", "barcode", "brand", "stock_uom"):
out[fieldname] = item.fields.get(fieldname)
@@ -211,22 +205,22 @@
get_field_precision(meta.get_field("plc_conversion_rate"),
webnotes._dict({"fields": args})))
-# def _get_item_discount(item_group, customer):
-# parent_item_groups = [x[0] for x in webnotes.conn.sql("""SELECT parent.name
-# FROM `tabItem Group` AS node, `tabItem Group` AS parent
-# WHERE parent.lft <= node.lft and parent.rgt >= node.rgt and node.name = %s
-# GROUP BY parent.name
-# ORDER BY parent.lft desc""", (item_group,))]
-#
-# discount = 0
-# for d in parent_item_groups:
-# res = webnotes.conn.sql("""select discount, name from `tabCustomer Discount`
-# where parent = %s and item_group = %s""", (customer, d))
-# if res:
-# discount = flt(res[0][0])
-# break
-#
-# return {"discount_percentage": discount}
+def get_item_discount(item_group, customer):
+ parent_item_groups = [x[0] for x in webnotes.conn.sql("""SELECT parent.name
+ FROM `tabItem Group` AS node, `tabItem Group` AS parent
+ WHERE parent.lft <= node.lft and parent.rgt >= node.rgt and node.name = %s
+ GROUP BY parent.name
+ ORDER BY parent.lft desc""", (item_group,))]
+
+ discount = 0
+ for d in parent_item_groups:
+ res = webnotes.conn.sql("""select discount, name from `tabCustomer Discount`
+ where parent = %s and item_group = %s""", (customer, d))
+ if res:
+ discount = flt(res[0][0])
+ break
+
+ return {"discount_percentage": discount}
def get_party_item_code(args, item_bean, out):
if args.transaction_type == "selling":
@@ -265,6 +259,15 @@
where ifnull(user,'') = '' and company = %s""", company, as_dict=1)
return pos_settings and pos_settings[0] or None
+
+def get_serial_nos_by_fifo(args, item_bean):
+ return "\n".join(webnotes.conn.sql_list("""select name from `tabSerial No`
+ where item_code=%(item_code)s and warehouse=%(warehouse)s and status='Available'
+ order by timestamp(purchase_date, purchase_time) asc limit %(qty)s""", {
+ "item_code": args.item_code,
+ "warehouse": args.warehouse,
+ "qty": cint(args.qty)
+ }))
@webnotes.whitelist()
def get_conversion_factor(item_code, uom):