minor fixes

This commit is contained in:
Nabin Hait 2014-02-12 14:53:18 +05:30
parent 0aa71a5c41
commit 139dc7b9b2
9 changed files with 130 additions and 162 deletions

View File

@ -73,43 +73,6 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
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");
},

View File

@ -90,7 +90,6 @@ class AccountsController(TransactionBase):
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 \

View File

@ -416,7 +416,7 @@ def get_bom_items_as_dict(bom, qty=1, fetch_exploded=1):
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

View File

@ -108,16 +108,22 @@ def execute():
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)
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(" ", "_")

View File

@ -110,6 +110,50 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
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 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
</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;

View File

@ -91,8 +91,8 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
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;

View File

@ -119,46 +119,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
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");
},

View File

@ -578,7 +578,7 @@ class DocType(StockController):
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"])

View File

@ -35,6 +35,9 @@ def get_item_details(args):
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 @@ def get_item_details(args):
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 @@ def validate_item_details(args, item):
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 @@ def validate_item_details(args, item):
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 @@ def get_basic_details(args, item_bean):
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 @@ def validate_conversion_rate(args, meta):
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 @@ def get_pos_settings(company):
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):