[fix] [minor] make_demo_fresh fixed

This commit is contained in:
Akhilesh Darjee 2013-11-27 16:16:32 +05:30
parent ca414a96cc
commit a8e704d4ab
4 changed files with 186 additions and 145 deletions

View File

@ -29,7 +29,7 @@ erpnext.POS = Class.extend({
</table>\ </table>\
</div>\ </div>\
<br>\ <br>\
<div class="net-total-area" style="margin-left: 40%;">\ <div class="totals-area" style="margin-left: 40%;">\
<table class="table table-condensed">\ <table class="table table-condensed">\
<tr>\ <tr>\
<td><b>Net Total</b></td>\ <td><b>Net Total</b></td>\
@ -48,13 +48,15 @@ erpnext.POS = Class.extend({
</tbody>\ </tbody>\
</table>\ </table>\
</div>\ </div>\
<table class="table table-condensed">\ <div class="grand-total-area">\
<tr>\ <table class="table table-condensed">\
<td style="vertical-align: middle;"><b>Grand Total</b></td>\ <tr>\
<td style="text-align: right; font-size: 200%; \ <td style="vertical-align: middle;"><b>Grand Total</b></td>\
font-size: bold;" class="grand-total"></td>\ <td style="text-align: right; font-size: 200%; \
</tr>\ font-size: bold;" class="grand-total"></td>\
</table>\ </tr>\
</table>\
</div>\
</div>\ </div>\
</div>\ </div>\
<br><br>\ <br><br>\
@ -72,17 +74,7 @@ erpnext.POS = Class.extend({
</div>\ </div>\
</div></div>'); </div></div>');
if (wn.meta.has_field(cur_frm.doc.doctype, "customer")) { this.check_transaction_type();
this.party = "Customer";
this.price_list = this.frm.doc.selling_price_list;
this.sales_or_purchase = "Sales";
}
else if (wn.meta.has_field(cur_frm.doc.doctype, "supplier")) {
this.party = "Supplier";
this.price_list = this.frm.doc.buying_price_list;
this.sales_or_purchase = "Purchase";
}
this.make(); this.make();
var me = this; var me = this;
@ -90,13 +82,33 @@ erpnext.POS = Class.extend({
me.refresh(); me.refresh();
}); });
this.wrapper.find(".delete-items").on("click", function() { this.call_function("delete-items", function() {me.remove_selected_item();});
me.remove_selected_item(); this.call_function("make-payment", function() {me.make_payment();});
}); },
check_transaction_type: function() {
var me = this;
this.wrapper.find(".make-payment").on("click", function() { // Check whether the transaction is "Sales" or "Purchase"
me.make_payment(); if (wn.meta.has_field(cur_frm.doc.doctype, "customer")) {
}); this.set_transaction_defaults("Customer", "export");
}
else if (wn.meta.has_field(cur_frm.doc.doctype, "supplier")) {
this.set_transaction_defaults("Supplier", "import");
}
},
set_transaction_defaults: function(party, export_or_import) {
var me = this;
this.party = party;
this.price_list = (party == "Customer" ?
this.frm.doc.selling_price_list : this.frm.doc.buying_price_list);
this.sales_or_purchase = (party == "Customer" ? "Sales" : "Purchase");
this.net_total = "net_total_" + export_or_import;
this.grand_total = "grand_total_" + export_or_import;
this.amount = export_or_import + "_amount";
this.rate = export_or_import + "_rate";
},
call_function: function(class_name, fn, event_name) {
this.wrapper.find("." + class_name).on(event_name || "click", fn);
}, },
make: function() { make: function() {
this.make_party(); this.make_party();
@ -148,19 +160,20 @@ erpnext.POS = Class.extend({
var me = this; var me = this;
this.search = wn.ui.form.make_control({ this.search = wn.ui.form.make_control({
df: { df: {
"fieldtype": "Link", "fieldtype": "Data",
"options": "Item",
"label": "Item", "label": "Item",
"fieldname": "pos_item", "fieldname": "pos_item",
"placeholder": "Item" "placeholder": "Search Item"
}, },
parent: this.wrapper.find(".search-area"), parent: this.wrapper.find(".search-area"),
only_input: true, only_input: true,
}); });
this.search.make_input(); this.search.make_input();
this.search.$input.on("change", function() { this.search.$input.on("keypress", function() {
if(!me.search.autocomplete_open) if(!me.search.autocomplete_open)
me.make_item_list(); if(me.item_timeout)
clearTimeout(me.item_timeout);
me.item_timeout = setTimeout(function() { me.make_item_list(); }, 1000);
}); });
}, },
make_barcode: function() { make_barcode: function() {
@ -184,6 +197,7 @@ erpnext.POS = Class.extend({
}, },
make_item_list: function() { make_item_list: function() {
var me = this; var me = this;
me.item_timeout = null;
wn.call({ wn.call({
method: 'accounts.doctype.sales_invoice.pos.get_items', method: 'accounts.doctype.sales_invoice.pos.get_items',
args: { args: {
@ -195,26 +209,28 @@ erpnext.POS = Class.extend({
callback: function(r) { callback: function(r) {
var $wrap = me.wrapper.find(".item-list"); var $wrap = me.wrapper.find(".item-list");
me.wrapper.find(".item-list").empty(); me.wrapper.find(".item-list").empty();
$.each(r.message, function(index, obj) { if (r.message) {
if (obj.image) $.each(r.message, function(index, obj) {
image = '<img src="' + obj.image + '" class="img-responsive" \ if (obj.image)
style="border:1px solid #eee; max-height: 140px;">'; image = '<img src="' + obj.image + '" class="img-responsive" \
else style="border:1px solid #eee; max-height: 140px;">';
image = '<div class="missing-image"><i class="icon-camera"></i></div>'; else
image = '<div class="missing-image"><i class="icon-camera"></i></div>';
$(repl('<div class="col-xs-3 pos-item" data-item_code="%(item_code)s">\ $(repl('<div class="col-xs-3 pos-item" data-item_code="%(item_code)s">\
<div style="height: 140px; overflow: hidden;">%(item_image)s</div>\ <div style="height: 140px; overflow: hidden;">%(item_image)s</div>\
<div class="small">%(item_code)s</div>\ <div class="small">%(item_code)s</div>\
<div class="small">%(item_name)s</div>\ <div class="small">%(item_name)s</div>\
<div class="small">%(item_price)s</div>\ <div class="small">%(item_price)s</div>\
</div>', </div>',
{ {
item_code: obj.name, item_code: obj.name,
item_price: format_currency(obj.ref_rate, obj.currency), item_price: format_currency(obj.ref_rate, obj.currency),
item_name: obj.name===obj.item_name ? "" : obj.item_name, item_name: obj.name===obj.item_name ? "" : obj.item_name,
item_image: image item_image: image
})).appendTo($wrap); })).appendTo($wrap);
}); });
}
// if form is local then allow this function // if form is local then allow this function
$(me.wrapper).find("div.pos-item").on("click", function() { $(me.wrapper).find("div.pos-item").on("click", function() {
@ -259,25 +275,42 @@ erpnext.POS = Class.extend({
// if item not found then add new item // if item not found then add new item
if (!caught) { if (!caught) {
var child = wn.model.add_child(me.frm.doc, this.frm.doctype + " Item", this.add_new_item_to_grid(item_code, serial_no);
this.frm.cscript.fname); }
child.item_code = item_code;
this.refresh();
if (serial_no) this.refresh_search_box();
child.serial_no = serial_no; },
add_new_item_to_grid: function(item_code, serial_no) {
me.frm.script_manager.trigger("item_code", child.doctype, child.name); var me = this;
var child = wn.model.add_child(me.frm.doc, this.frm.doctype + " Item",
this.frm.cscript.fname);
child.item_code = item_code;
if (serial_no)
child.serial_no = serial_no;
this.frm.script_manager.trigger("item_code", child.doctype, child.name);
},
refresh_search_box: function() {
var me = this;
// Clear Item Box and remake item list
if (this.search.$input.val()) {
this.search.set_input("");
this.make_item_list();
} }
me.refresh();
}, },
update_qty: function(item_code, qty) { update_qty: function(item_code, qty) {
var me = this; var me = this;
$.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name, $.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name,
this.frm.cscript.fname, this.frm.doctype), function(i, d) { this.frm.cscript.fname, this.frm.doctype), function(i, d) {
if (d.item_code == item_code) { if (d.item_code == item_code) {
if (qty == 0) if (qty == 0) {
wn.model.clear_doc(d.doctype, d.name); wn.model.clear_doc(d.doctype, d.name);
else { me.refresh_grid();
} else {
d.qty = qty; d.qty = qty;
me.frm.script_manager.trigger("qty", d.doctype, d.name); me.frm.script_manager.trigger("qty", d.doctype, d.name);
} }
@ -289,22 +322,34 @@ erpnext.POS = Class.extend({
var me = this; var me = this;
this.party_field.set_input(this.frm.doc[this.party.toLowerCase()]); this.party_field.set_input(this.frm.doc[this.party.toLowerCase()]);
this.barcode.set_input(""); this.barcode.set_input("");
this.total_flat_discount = 0.0;
// add items this.show_items_in_item_cart();
var $items = me.wrapper.find("#cart tbody").empty(); this.show_taxes();
this.set_totals();
// if form is local then only run all these functions
if (this.frm.doc.docstatus===0) {
this.call_when_local();
}
this.disable_text_box_and_button();
this.make_payment_button();
// If quotation to is not Customer then remove party
if (this.frm.doctype == "Quotation") {
this.party_field.$wrapper.remove();
if (this.frm.doc.quotation_to == "Customer")
this.make_party();
}
},
show_items_in_item_cart: function() {
var me = this;
var $items = this.wrapper.find("#cart tbody").empty();
$.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name, $.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name,
this.frm.cscript.fname, this.frm.doctype), function(i, d) { this.frm.cscript.fname, this.frm.doctype), function(i, d) {
if (me.sales_or_purchase == "Sales") {
item_amount = d.export_amount;
rate = d.export_rate;
}
else {
item_amount = d.import_amount;
rate = d.import_rate;
}
$(repl('<tr id="%(item_code)s" data-selected="false">\ $(repl('<tr id="%(item_code)s" data-selected="false">\
<td>%(item_code)s%(item_name)s</td>\ <td>%(item_code)s%(item_name)s</td>\
<td><input type="text" value="%(qty)s" \ <td><input type="text" value="%(qty)s" \
@ -315,76 +360,73 @@ erpnext.POS = Class.extend({
item_code: d.item_code, item_code: d.item_code,
item_name: d.item_name===d.item_code ? "" : ("<br>" + d.item_name), item_name: d.item_name===d.item_code ? "" : ("<br>" + d.item_name),
qty: d.qty, qty: d.qty,
rate: format_currency(rate, me.frm.doc.currency), rate: format_currency(d[me.rate], me.frm.doc.currency),
amount: format_currency(item_amount, me.frm.doc.currency) amount: format_currency(d[me.amount], me.frm.doc.currency)
} }
)).appendTo($items); )).appendTo($items);
}); });
},
// taxes show_taxes: function() {
var me = this;
var taxes = wn.model.get_children(this.sales_or_purchase + " Taxes and Charges", var taxes = wn.model.get_children(this.sales_or_purchase + " Taxes and Charges",
this.frm.doc.name, this.frm.cscript.other_fname, this.frm.doctype); this.frm.doc.name, this.frm.cscript.other_fname, this.frm.doctype);
$(this.wrapper).find(".tax-table") $(this.wrapper).find(".tax-table")
.toggle((taxes && taxes.length) ? true : false) .toggle((taxes && taxes.length &&
flt(me.frm.doc.other_charges_total_export ||
me.frm.doc.other_charges_added_import) != 0.0) ? true : false)
.find("tbody").empty(); .find("tbody").empty();
$.each(taxes, function(i, d) { $.each(taxes, function(i, d) {
$(repl('<tr>\ if (d.charge_type == "Discount Amount") {
<td>%(description)s (%(rate)s%)</td>\ me.total_flat_discount += flt(d.rate);
<td style="text-align: right;">%(tax_amount)s</td>\ } else {
<tr>', { $(repl('<tr>\
description: d.description, <td>%(description)s %(rate)s</td>\
rate: d.rate, <td style="text-align: right;">%(tax_amount)s</td>\
tax_amount: format_currency(flt(d.tax_amount)/flt(me.frm.doc.conversion_rate), <tr>', {
me.frm.doc.currency) description: d.description,
})).appendTo(".tax-table tbody"); rate: ((d.charge_type == "Actual") ? '' : ("(" + d.rate + "%)")),
tax_amount: format_currency(flt(d.tax_amount)/flt(me.frm.doc.conversion_rate),
me.frm.doc.currency)
})).appendTo(".tax-table tbody");
}
});
},
set_totals: function() {
var me = this;
this.wrapper.find(".net-total").text(format_currency(this.frm.doc[this.net_total],
me.frm.doc.currency));
this.wrapper.find(".grand-total").text(format_currency(this.frm.doc[this.grand_total],
me.frm.doc.currency));
},
call_when_local: function() {
var me = this;
// append quantity to the respective item after change from input box
$(this.wrapper).find("input.qty").on("change", function() {
var item_code = $(this).closest("tr")[0].id;
me.update_qty(item_code, $(this).val());
}); });
// set totals // on td click toggle the highlighting of row
if (this.sales_or_purchase == "Sales") { $(this.wrapper).find("#cart tbody tr td").on("click", function() {
this.wrapper.find(".net-total").text(format_currency(this.frm.doc.net_total_export, var row = $(this).closest("tr");
me.frm.doc.currency)); if (row.attr("data-selected") == "false") {
this.wrapper.find(".grand-total").text(format_currency(this.frm.doc.grand_total_export, row.attr("class", "warning");
me.frm.doc.currency)); row.attr("data-selected", "true");
} }
else { else {
this.wrapper.find(".net-total").text(format_currency(this.frm.doc.net_total_import, row.prop("class", null);
me.frm.doc.currency)); row.attr("data-selected", "false");
this.wrapper.find(".grand-total").text(format_currency(this.frm.doc.grand_total_import, }
me.frm.doc.currency));
}
// if form is local then only run all these functions
if (this.frm.doc.docstatus===0) {
$(this.wrapper).find("input.qty").on("focus", function() {
$(this).select();
});
// append quantity to the respective item after change from input box
$(this.wrapper).find("input.qty").on("change", function() {
var item_code = $(this).closest("tr")[0].id;
me.update_qty(item_code, $(this).val());
});
// on td click toggle the highlighting of row
$(this.wrapper).find("#cart tbody tr td").on("click", function() {
var row = $(this).closest("tr");
if (row.attr("data-selected") == "false") {
row.attr("class", "warning");
row.attr("data-selected", "true");
}
else {
row.prop("class", null);
row.attr("data-selected", "false");
}
me.refresh_delete_btn();
});
me.refresh_delete_btn(); me.refresh_delete_btn();
this.barcode.$input.focus(); });
}
me.refresh_delete_btn();
this.barcode.$input.focus();
},
disable_text_box_and_button: function() {
var me = this;
// if form is submitted & cancelled then disable all input box & buttons // if form is submitted & cancelled then disable all input box & buttons
if (this.frm.doc.docstatus>=1) { if (this.frm.doc.docstatus>=1) {
$(this.wrapper).find('input, button').each(function () { $(this.wrapper).find('input, button').each(function () {
@ -399,17 +441,12 @@ erpnext.POS = Class.extend({
}); });
$(this.wrapper).find(".make-payment").show(); $(this.wrapper).find(".make-payment").show();
} }
},
make_payment_button: function() {
var me = this;
// Show Make Payment button only in Sales Invoice // Show Make Payment button only in Sales Invoice
if (this.frm.doctype != "Sales Invoice") if (this.frm.doctype != "Sales Invoice")
$(this.wrapper).find(".make-payment").hide(); $(this.wrapper).find(".make-payment").hide();
// If quotation to is not Customer then remove party
if (this.frm.doctype == "Quotation") {
this.party_field.$wrapper.remove();
if (this.frm.doc.quotation_to == "Customer")
this.make_party();
}
}, },
refresh_delete_btn: function() { refresh_delete_btn: function() {
$(this.wrapper).find(".delete-items").toggle($(".item-cart .warning").length ? true : false); $(this.wrapper).find(".delete-items").toggle($(".item-cart .warning").length ? true : false);
@ -455,9 +492,12 @@ erpnext.POS = Class.extend({
} }
} }
}); });
this.refresh_grid();
},
refresh_grid: function() {
this.frm.fields_dict[this.frm.cscript.fname].grid.refresh(); this.frm.fields_dict[this.frm.cscript.fname].grid.refresh();
this.frm.script_manager.trigger("calculate_taxes_and_totals"); this.frm.script_manager.trigger("calculate_taxes_and_totals");
me.refresh(); this.refresh();
}, },
make_payment: function() { make_payment: function() {
var me = this; var me = this;
@ -489,8 +529,6 @@ erpnext.POS = Class.extend({
"total_amount": $(".grand-total").text() "total_amount": $(".grand-total").text()
}); });
dialog.show(); dialog.show();
me.barcode.$input.focus();
dialog.get_input("total_amount").prop("disabled", true); dialog.get_input("total_amount").prop("disabled", true);
dialog.fields_dict.pay.input.onclick = function() { dialog.fields_dict.pay.input.onclick = function() {

View File

@ -7,6 +7,7 @@ import webnotes
@webnotes.whitelist() @webnotes.whitelist()
def get_items(price_list, sales_or_purchase, item=None, item_group=None): def get_items(price_list, sales_or_purchase, item=None, item_group=None):
condition = "" condition = ""
args = {"price_list": price_list}
if sales_or_purchase == "Sales": if sales_or_purchase == "Sales":
condition = "i.is_sales_item='Yes'" condition = "i.is_sales_item='Yes'"
@ -17,7 +18,8 @@ def get_items(price_list, sales_or_purchase, item=None, item_group=None):
condition += " and i.item_group='%s'" % item_group condition += " and i.item_group='%s'" % item_group
if item: if item:
condition += " and i.name='%s'" % item condition += " and CONCAT(i.name, i.item_name) like %(name)s"
args["name"] = "%%%s%%" % item
return webnotes.conn.sql("""select i.name, i.item_name, i.image, return webnotes.conn.sql("""select i.name, i.item_name, i.image,
item_det.ref_rate, item_det.currency item_det.ref_rate, item_det.currency
@ -27,7 +29,7 @@ def get_items(price_list, sales_or_purchase, item=None, item_group=None):
ON ON
item_det.item_code=i.name item_det.item_code=i.name
where where
%s""" % ('%s', condition), (price_list), as_dict=1) %s""" % ('%(price_list)s', condition), args, as_dict=1)
@webnotes.whitelist() @webnotes.whitelist()
def get_item_code(barcode_serial_no): def get_item_code(barcode_serial_no):

View File

@ -14,9 +14,9 @@ You can only upload upto 5000 records in one go. (may be less in some cases),,,,
DocType:,Fiscal Year,,, DocType:,Fiscal Year,,,
Column Labels:,ID,Year Name,Year Start Date,Year Closed Column Labels:,ID,Year Name,Year Start Date,Year Closed
Column Name:,name,year,year_start_date,year_end_date,is_fiscal_year_closed Column Name:,name,year,year_start_date,year_end_date,is_fiscal_year_closed
Mandatory:,Yes,Yes,Yes,No Mandatory:,Yes,Yes,Yes,Yes,No
Type:,Data (text),Data,Date,Select Type:,Data (text),Data,Date,Date,Select
Info:,,,,"One of: No, Yes" Info:,,,,,"One of: No, Yes"
Start entering data below this line,,,, Start entering data below this line,,,,
,,2009,01-01-2009,31-12-2009,No ,,2009,01-01-2009,31-12-2009,No
,,2010,01-01-2010,31-12-2010,No ,,2010,01-01-2010,31-12-2010,No

Can't render this file because it has a wrong number of fields in line 16.

View File

@ -380,7 +380,8 @@ def complete_setup():
setup_account({ setup_account({
"first_name": "Test", "first_name": "Test",
"last_name": "User", "last_name": "User",
"fy_start": "1st Jan", "fy_start_date": "2013-01-01",
"fy_end_date": "2013-12-31",
"industry": "Manufacturing", "industry": "Manufacturing",
"company_name": company, "company_name": company,
"company_abbr": company_abbr, "company_abbr": company_abbr,