[pos] [cleanup]

This commit is contained in:
Rushabh Mehta 2013-08-23 13:16:22 +05:30
parent d491012009
commit 16a62fa4be
5 changed files with 141 additions and 89 deletions

View File

@ -7,56 +7,66 @@ erpnext.POS = Class.extend({
this.frm = frm;
this.wrapper.html('<div class="container">\
<div class="row">\
<div class="col-lg-4">\
<div class="customer-area"></div>\
<div class="button-area">\
<div class="col-lg-6">\
<a class="btn btn-danger col-lg-12 delete-items">\
<i class="icon-trash icon-large"></i></a></div>\
<div class="col-lg-6">\
<a class="btn btn-success col-lg-12 make-payment">\
<i class="icon-money icon-large"></i></a></div>\
</div>\
<div>&nbsp;</div>\
<div class="item-cart">\
<table class="table table-condensed">\
<tr>\
<th>Item</th>\
<th>#</th>\
<th>Rate</th>\
<th>Amount</th>\
</tr>\
</table>\
<div>\
<table id="cart" class="table table-condensed table-hover">\
<div class="customer-area col-sm-3 col-xs-6"></div>\
<div class="barcode-area col-sm-3 col-xs-6"></div>\
<div class="search-area col-sm-3 col-xs-6"></div>\
<div class="item-group-area col-sm-3 col-xs-6"></div>\
</div>\
<div class="row">\
<div class="col-sm-6">\
<div class="pos-bill">\
<div class="item-cart">\
<table class="table table-condensed table-hover" id="cart" style="table-layout: fixed;">\
<thead>\
<tr>\
<th style="width: 50%">Item</th>\
<th style="width: 25%; text-align: right;">Qty</th>\
<th style="width: 25%; text-align: right;">Rate</th>\
</tr>\
</thead>\
<tbody>\
</tbody>\
</table>\
</div>\
<br>\
<div class="net-total-area" style="margin-left: 40%;">\
<table class="table table-condensed">\
<tr>\
<td><b>Net Total</b></td>\
<td style="text-align: right;" class="net-total"></td>\
</tr>\
</table>\
<div class="tax-table" style="display: none;">\
<table class="table table-condensed">\
<thead>\
<tr>\
<th style="width: 60%">Taxes</th>\
<th style="width: 40%; text-align: right;"></th>\
</tr>\
</thead>\
<tbody>\
</tbody>\
</table>\
</div>\
<table class="table table-condensed">\
<tr>\
<td style="vertical-align: middle;"><b>Grand Total</b></td>\
<td style="text-align: right; font-size: 200%; \
font-size: bold;" class="grand-total"></td>\
</tr>\
</table>\
</div>\
</div>\
<div>&nbsp;</div>\
<div class="net-total-area" style="font-weight:bold;">\
<div class="col-lg-6">Net Total</div>\
<div class="col-lg-6 net-total">&nbsp;</div>\
</div>\
<div class="tax-area" style="font-weight:bold;">\
<div class="col-lg-6">Tax</div>\
<div class="col-lg-6 tax">&nbsp;</div>\
</div>\
<div class="grand-total-area" style="font-weight:bold;">\
<div class="col-lg-6">Grand Total</div>\
<div class="col-lg-6 grand-total">&nbsp;</div>\
</div>\
<br><br>\
<button class="btn btn-success btn-lg make-payment">\
<i class="icon-money"></i> Make Payment</button>\
<button class="btn btn-default btn-lg delete-items pull-right" style="display: none;">\
<i class="icon-trash"></i> Del</button>\
<br><br>\
</div>\
<div class="col-lg-8">\
<div class="search-fields-area">\
<div class="col-lg-4">\
<div class="barcode-area"></div></div>\
<div class="col-lg-4">\
<div class="search-area"></div></div>\
<div class="col-lg-4">\
<div class="item-group-area"></div></div>\
</div>\
<div class="col-sm-6">\
<div class="item-list-area">\
<div class="col-lg-12">\
<div class="col-sm-12">\
<div class="row item-list"></div></div>\
</div>\
</div>\
@ -91,7 +101,8 @@ erpnext.POS = Class.extend({
"fieldtype": "Link",
"options": "Customer",
"label": "Customer",
"fieldname": "pos_customer"
"fieldname": "pos_customer",
"placeholder": "Customer"
},
parent: this.wrapper.find(".customer-area")
});
@ -108,7 +119,8 @@ erpnext.POS = Class.extend({
"fieldtype": "Link",
"options": "Item Group",
"label": "Item Group",
"fieldname": "pos_item_group"
"fieldname": "pos_item_group",
"placeholder": "Filter by Item Group"
},
parent: this.wrapper.find(".item-group-area")
});
@ -125,7 +137,8 @@ erpnext.POS = Class.extend({
"fieldtype": "Link",
"options": "Item",
"label": "Item",
"fieldname": "pos_item"
"fieldname": "pos_item",
"placeholder": "Select Item"
},
parent: this.wrapper.find(".search-area")
});
@ -141,7 +154,8 @@ erpnext.POS = Class.extend({
df: {
"fieldtype": "Data",
"label": "Barcode",
"fieldname": "pos_barcode"
"fieldname": "pos_barcode",
"placeholder": "Select Barcode"
},
parent: this.wrapper.find(".barcode-area")
});
@ -164,28 +178,30 @@ erpnext.POS = Class.extend({
me.wrapper.find(".item-list").empty();
$.each(r.message, function(index, obj) {
if (obj.image)
image = "<img src='" + obj.image + "' width='112px' height='125px'>";
image = "<img src='" + obj.image + "' class='img-responsive'>";
else
image = "<div class='missing-image'><i class='icon-camera'></i></div>";
image = '<div class="missing-image"><i class="icon-camera"></i></div>';
$(repl('<div class="col-lg-3 item">\
<a data-item_code="%(item_code)s">\
<table>\
<tr><td colspan="2">%(item_image)s</td></tr>\
<tr><td>%(item_code)s</td>\
<td rowspan="2">%(item_price)s</td></tr>\
<tr><td>%(item_name)s</td>\
</tr></table></a></div>',
$(repl('<div class="col-xs-3 pos-item" data-item_code="%(item_code)s">\
%(item_image)s\
<div class="small">%(item_code)s</div>\
<div class="small">%(item_name)s</div>\
<div class="small">%(item_price)s</div>\
</div>',
{
item_code: obj.name,
item_price: format_currency(obj.ref_rate, obj.ref_currency),
item_name: obj.item_name,
item_name: obj.name===obj.item_name ? "" : obj.item_name,
item_image: image
})).appendTo($wrap);
});
$("div.item").on("click", function() {
me.add_to_cart($(this).find("a").attr("data-item_code"));
$("div.pos-item").on("click", function() {
if(!cur_frm.doc.customer) {
msgprint("Please select customer first.");
return;
}
me.add_to_cart($(this).attr("data-item_code"));
});
}
});
@ -195,7 +211,7 @@ erpnext.POS = Class.extend({
var caught = false;
// get no_of_items
no_of_items = me.wrapper.find("#cart tr").length;
no_of_items = me.wrapper.find("#cart tbody").length;
// check whether the item is already added
if (no_of_items != 0) {
@ -214,7 +230,7 @@ erpnext.POS = Class.extend({
var child = wn.model.add_child(me.frm.doc, "Sales Invoice Item", "entries");
child.item_code = item_code;
me.frm.cscript.item_code(me.frm.doc, child.doctype, child.name);
me.refresh();
//me.refresh();
}
},
update_qty: function(item_code, qty) {
@ -238,18 +254,19 @@ erpnext.POS = Class.extend({
this.barcode.set_input("");
// add items
var $items = me.wrapper.find("#cart").empty();
var $items = me.wrapper.find("#cart tbody").empty();
$.each(wn.model.get_children("Sales Invoice Item", this.frm.doc.name, "entries",
"Sales Invoice"), function(i, d) {
"Sales Invoice"), function(i, d) {
$(repl('<tr id="%(item_code)s" data-selected="false">\
<td>%(item_code)s <br> %(item_name)s</td>\
<td><input type="text" value="%(qty)s" class="form-control qty"></td>\
<td>%(rate)s</td>\
<td>%(amount)s</td></tr>',
<td>%(item_code)s%(item_name)s</td>\
<td><input type="text" value="%(qty)s" \
class="form-control qty" style="text-align: right;"></td>\
<td style="text-align: right;">%(rate)s<br><b>%(amount)s</b></td>\
</tr>',
{
item_code: d.item_code,
item_name: d.item_name,
item_name: d.item_name===d.item_code ? "" : ("<br>" + d.item_name),
qty: d.qty,
rate: format_currency(d.ref_rate, cur_frm.doc.price_list_currency),
amount: format_currency(d.export_amount, cur_frm.doc.price_list_currency)
@ -257,11 +274,26 @@ erpnext.POS = Class.extend({
)).appendTo($items);
});
// taxes
var taxes = wn.model.get_children("Sales Taxes and Charges", this.frm.doc.name, "other_charges",
"Sales Invoice");
$(".tax-table")
.toggle((taxes && taxes.length) ? true : false)
.find("tbody").empty();
$.each(taxes, function(i, d) {
$(repl('<tr>\
<td>%(description)s</td>\
<td style="text-align: right;">%(tax_amount)s</td>\
<tr>', {
description: d.description,
tax_amount: format_currency(d.tax_amount, me.frm.doc.price_list_currency)
})).appendTo(".tax-table tbody")
});
// set totals
this.wrapper.find(".net-total").text(format_currency(this.frm.doc.net_total_export,
cur_frm.doc.price_list_currency));
this.wrapper.find(".tax").text(format_currency(this.frm.doc.other_charges_total_export,
cur_frm.doc.price_list_currency));
this.wrapper.find(".grand-total").text(format_currency(this.frm.doc.grand_total_export,
cur_frm.doc.price_list_currency));
@ -282,7 +314,14 @@ erpnext.POS = Class.extend({
row.prop("class", null);
row.attr("data-selected", "false");
}
me.refresh_delete_btn();
});
me.refresh_delete_btn();
},
refresh_delete_btn: function() {
$(".delete-items").toggle($(".item-cart .warning").length ? true : false);
},
add_item_thru_barcode: function() {
var me = this;
@ -302,9 +341,9 @@ erpnext.POS = Class.extend({
remove_selected_item: function() {
var me = this;
var selected_items = [];
var no_of_items = $("#cart tr").length;
var no_of_items = $("#cart tbody tr").length;
for(var x=0; x<=no_of_items - 1; x++) {
var row = $("#cart tr:eq(" + x + ")");
var row = $("#cart tbody tr:eq(" + x + ")");
if(row.attr("data-selected") == "true") {
selected_items.push(row.attr("id"));
}
@ -327,7 +366,7 @@ erpnext.POS = Class.extend({
},
make_payment: function() {
var me = this;
var no_of_items = $("#cart tr").length;
var no_of_items = $("#cart tbody tr").length;
var mode_of_payment = [];
if (no_of_items == 0)
@ -356,6 +395,8 @@ erpnext.POS = Class.extend({
});
dialog.show();
dialog.get_input("total_amount").attr("disabled", "disabled");
dialog.fields_dict.pay.input.onclick = function() {
cur_frm.set_value("mode_of_payment", dialog.get_values().mode_of_payment);
cur_frm.set_value("paid_amount", dialog.get_values().total_amount);

View File

@ -9,14 +9,18 @@ def get_items(price_list, item=None, item_group=None):
condition = ""
if item_group and item_group != "All Item Groups":
condition = "where i.item_group='%s'" % item_group
condition = "and i.item_group='%s'" % item_group
if item:
condition = "where i.name='%s'" % item
condition = "and i.name='%s'" % item
return webnotes.conn.sql("""select i.name, i.item_name, i.image, ip.ref_rate,
ip.ref_currency from `tabItem` i LEFT JOIN `tabItem Price` ip ON ip.parent=i.name
and ip.price_list=%s %s""" % ('%s', condition), (price_list), as_dict=1)
return webnotes.conn.sql("""select
i.name, i.item_name, i.image, ip.ref_rate, ip.ref_currency
from `tabItem` i LEFT JOIN `tabItem Price` ip
ON ip.parent=i.name
and ip.price_list=%s
where
i.is_sales_item='Yes'%s""" % ('%s', condition), (price_list), as_dict=1)
@webnotes.whitelist()
def get_item_from_barcode(barcode):

View File

@ -26,8 +26,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
}
}
pos_view = cint(sys_defaults.fs_pos_view);
if(this.frm.doc.is_pos && this.frm.doc.docstatus===0 && pos_view===1) {
if(this.frm.doc.is_pos && this.frm.doc.docstatus===0) {
cur_frm.cscript.toggle_pos(true);
}
},
@ -60,7 +59,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
cur_frm.add_custom_button('Make Payment Entry', cur_frm.cscript.make_bank_voucher);
}
if (this.frm.doc.docstatus===0) {
if (doc.docstatus===0) {
cur_frm.add_custom_button(wn._('From Sales Order'),
function() {
wn.model.map_current_doc({
@ -97,11 +96,18 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
if (cint(sys_defaults.fs_pos_view)===1)
cur_frm.cscript.pos_btn();
setTimeout(function() { cur_frm.$pos_btn.click(); }, 1000);
} else {
// hide shown pos for submitted records
if(cur_frm.pos_active) cur_frm.cscript.toggle_pos(false);
}
},
pos_btn: function() {
if(cur_frm.$pos_btn) cur_frm.$pos_btn.remove();
if(cur_frm.$pos_btn)
cur_frm.$pos_btn.remove();
if(!cur_frm.pos_active) {
var btn_label = wn._("POS View"),
@ -111,11 +117,11 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
icon = "icon-file-text";
}
cur_frm.add_custom_button(btn_label, function() {
cur_frm.$pos_btn = $(this);
cur_frm.$pos_btn = cur_frm.add_custom_button(btn_label, function() {
cur_frm.cscript.toggle_pos();
cur_frm.cscript.pos_btn();
}, icon);
},
toggle_pos: function(show) {

View File

@ -72,7 +72,7 @@ def feature_setup():
'fs_exports', 'fs_imports', 'fs_discounts', 'fs_purchase_discounts',
'fs_after_sales_installations', 'fs_projects', 'fs_sales_extras',
'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality',
'fs_page_break', 'fs_more_info'
'fs_page_break', 'fs_more_info', 'fs_pos_view'
]
doc.fields.update(dict(zip(flds, [1]*len(flds))))
doc.save()

View File

@ -24,13 +24,14 @@ bank_name = "Citibank"
runs_for = 20
prob = {
"default": { "make": 0.6, "qty": (1,5) },
"Sales Order": { "make": 0.4, "qty": (1,3) },
"Purchase Order": { "make": 0.7, "qty": (1,15) },
"Purchase Receipt": { "make": 0.7, "qty": (1,15) },
}
def make(reset=False):
webnotes.connect()
webnotes.print_messages = True
#webnotes.print_messages = True
webnotes.mute_emails = True
webnotes.rollback_on_exception = True