[design] POS - item grid and taxes

This commit is contained in:
Anand Doshi 2015-01-05 16:19:12 +05:30
parent ff58261407
commit 9b955feff8
13 changed files with 147 additions and 155 deletions

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe import frappe
@frappe.whitelist() @frappe.whitelist()
def get_items(price_list, sales_or_purchase, item=None, item_group=None): def get_items(price_list, sales_or_purchase, item=None):
condition = "" condition = ""
args = {"price_list": price_list} args = {"price_list": price_list}
@ -14,10 +14,21 @@ def get_items(price_list, sales_or_purchase, item=None, item_group=None):
else: else:
condition = "i.is_purchase_item='Yes'" condition = "i.is_purchase_item='Yes'"
if item_group and item_group != "All Item Groups":
condition += " and i.item_group='%s'" % item_group.replace("'", "\'")
if item: if item:
# search serial no
item_code = frappe.db.sql("""select name as serial_no, item_code
from `tabSerial No` where name=%s""", (item), as_dict=1)
if item_code:
item_code[0]["name"] = item_code[0]["item_code"]
return item_code
# search barcode
item_code = frappe.db.sql("""select name from `tabItem` where barcode=%s""",
(item), as_dict=1)
if item_code:
item_code[0]["barcode"] = item
return item_code
condition += " and CONCAT(i.name, i.item_name) like %(name)s" condition += " and CONCAT(i.name, i.item_name) like %(name)s"
args["name"] = "%%%s%%" % item args["name"] = "%%%s%%" % item
@ -31,21 +42,21 @@ def get_items(price_list, sales_or_purchase, item=None, item_group=None):
where where
%s""" % ('%(price_list)s', condition), args, as_dict=1) %s""" % ('%(price_list)s', condition), args, as_dict=1)
@frappe.whitelist() # @frappe.whitelist()
def get_item_code(barcode_serial_no): # def get_item_code(barcode_serial_no):
input_via = "serial_no" # input_via = "serial_no"
item_code = frappe.db.sql("""select name, item_code from `tabSerial No` where # item_code = frappe.db.sql("""select name, item_code from `tabSerial No` where
name=%s""", (barcode_serial_no), as_dict=1) # name=%s""", (barcode_serial_no), as_dict=1)
#
if not item_code: # if not item_code:
input_via = "barcode" # input_via = "barcode"
item_code = frappe.db.sql("""select name from `tabItem` where barcode=%s""", # item_code = frappe.db.sql("""select name from `tabItem` where barcode=%s""",
(barcode_serial_no), as_dict=1) # (barcode_serial_no), as_dict=1)
#
if item_code: # if item_code:
return item_code, input_via # return item_code, input_via
else: # else:
frappe.throw(frappe._("Invalid Barcode or Serial No")) # frappe.throw(frappe._("Invalid Barcode or Serial No"))
@frappe.whitelist() @frappe.whitelist()
def get_mode_of_payment(): def get_mode_of_payment():

View File

@ -293,12 +293,12 @@ cur_frm.fields_dict.debit_to.get_query = function(doc) {
cur_frm.fields_dict.cash_bank_account.get_query = function(doc) { cur_frm.fields_dict.cash_bank_account.get_query = function(doc) {
return { return {
filters: { filters: [
'account_type': 'Receivable', ["Account", "account_type", "in", ["Cash", "Bank"]],
'root_type': 'Asset', ["Account", "root_type", "=", "Asset"],
'group_or_ledger': 'Ledger', ["Account", "group_or_ledger", "=", "Ledger"],
'company': doc.company ["Account", "company", "=", doc.company]
} ]
} }
} }

View File

@ -12,7 +12,7 @@ from frappe.model.document import Document
class Project(Document): class Project(Document):
def get_feed(self): def get_feed(self):
return self.status return '{0}: {1}'.format(_(self.status), self.project_name)
def get_gross_profit(self): def get_gross_profit(self):
pft, per_pft =0, 0 pft, per_pft =0, 0

View File

@ -16,6 +16,8 @@
"public/js/templates/contact_list.html", "public/js/templates/contact_list.html",
"public/js/pos/pos.html", "public/js/pos/pos.html",
"public/js/pos/pos_bill_item.html", "public/js/pos/pos_bill_item.html",
"public/js/pos/pos_item.html",
"public/js/pos/pos_tax_row.html",
"public/js/pos/pos.js" "public/js/pos/pos.js"
], ],
"css/shopping-cart-web.css": [ "css/shopping-cart-web.css": [

View File

@ -20,11 +20,32 @@
} }
.pos-item { .pos-item {
height: 200px; display: inline-block;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis;
cursor: pointer; cursor: pointer;
padding-left: 5px !important; padding: 10px;
padding-right: 5px !important; height: 0px;
padding-bottom: 35%;
width: 30%;
margin: 1.6%;
border: 1px solid #d1d8dd;
}
.pos-item .item-code {
margin-bottom: 0px;
}
.pos-item .no-image {
background-color: #fafbfc;
border: 1px dashed #d1d8dd;
}
.pos-item-image {
padding-bottom: 100%;
background-size: cover;
background-position: center;
border: 1px solid transparent;
} }
.pos-item-area { .pos-item-area {
@ -38,7 +59,7 @@
} }
.item-list-area { .item-list-area {
padding: 15px; padding: 15px 0px;
} }
.pos-toolbar, .pos-bill-toolbar { .pos-toolbar, .pos-bill-toolbar {
@ -54,7 +75,7 @@
.pos-bill-wrapper { .pos-bill-wrapper {
border: 1px solid #d1d8dd; border: 1px solid #d1d8dd;
border-top: none; border-top: none;
border-right: none; margin-right: -1px;
} }
.pos-bill { .pos-bill {
@ -82,7 +103,15 @@
} }
.pos-qty-btn { .pos-qty-btn {
margin-top: 5px; margin-top: 3px;
cursor: pointer; cursor: pointer;
font-size: 120%; font-size: 120%;
} }
.pos .search-area .form-group {
max-width: 100% !important;
}
.pos .tax-table {
margin-bottom: 10px;
}

View File

@ -2,9 +2,9 @@
<div class="row"> <div class="row">
<div class="col-sm-5 pos-bill-wrapper"> <div class="col-sm-5 pos-bill-wrapper">
<div class="pos-bill-toolbar row"> <div class="pos-bill-toolbar row">
<div class="party-area col-xs-6"></div> <div class="party-area col-xs-9"></div>
<div class="col-xs-6"> <div class="col-xs-3 text-right">
<button class="btn btn-success make-payment">{%= __("Pay") %}</button> <button class="btn btn-success make-payment hide">{%= __("Pay") %}</button>
</div> </div>
</div> </div>
<div class="pos-bill"> <div class="pos-bill">
@ -21,8 +21,11 @@
<div class="col-xs-6"><h6 class="text-muted">{%= __("Net Total") %}</h6></div> <div class="col-xs-6"><h6 class="text-muted">{%= __("Net Total") %}</h6></div>
<div class="col-xs-6"><h6 class="net-total text-right"></h6></div> <div class="col-xs-6"><h6 class="net-total text-right"></h6></div>
</div> </div>
<div class="tax-table hide"> <div class="row pos-bill-row tax-area hide">
<div class="col-xs-12 text-muted">
<h6>{%= __("Taxes") %}</h6> <h6>{%= __("Taxes") %}</h6>
<div class="tax-table small"></div>
</div>
</div> </div>
<div class="row pos-bill-row discount-amount-area"> <div class="row pos-bill-row discount-amount-area">
<div class="col-xs-6"><h6 class="text-muted">{%= __("Discount Amount") %}</h6></div> <div class="col-xs-6"><h6 class="text-muted">{%= __("Discount Amount") %}</h6></div>
@ -41,14 +44,10 @@
</div> </div>
<div class="col-sm-7 pos-item-area"> <div class="col-sm-7 pos-item-area">
<div class="row pos-item-toolbar"> <div class="row pos-item-toolbar">
<div class="barcode-area col-xs-4"></div> <div class="search-area col-xs-12"></div>
<div class="search-area col-xs-4"></div>
<div class="item-group-area col-xs-4"></div>
</div>
<div class="item-list-area row">
<div class="col-sm-12">
<div class="row item-list"></div>
</div> </div>
<div class="item-list-area">
<div class="item-list"></div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -19,8 +19,9 @@ erpnext.POS = Class.extend({
frappe.model.set_value(me.frm.doctype, me.frm.docname, "discount_amount", this.value); frappe.model.set_value(me.frm.doctype, me.frm.docname, "discount_amount", this.value);
}); });
this.call_function("remove-items", function() {me.remove_selected_items();}); this.wrapper.find(".make-payment").on("click", function() {
this.call_function("make-payment", function() {me.make_payment();}); me.make_payment();
})
}, },
check_transaction_type: function() { check_transaction_type: function() {
var me = this; var me = this;
@ -45,14 +46,9 @@ erpnext.POS = Class.extend({
// this.amount = export_or_import + "_amount"; // this.amount = export_or_import + "_amount";
// this.rate = export_or_import + "_rate"; // 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();
this.make_barcode();
this.make_search(); this.make_search();
this.make_item_group();
this.make_item_list(); this.make_item_list();
}, },
make_party: function() { make_party: function() {
@ -75,25 +71,6 @@ erpnext.POS = Class.extend({
me.party.toLowerCase(), this.value); me.party.toLowerCase(), this.value);
}); });
}, },
make_barcode: function() {
var me = this;
this.barcode = frappe.ui.form.make_control({
df: {
"fieldtype": "Data",
"label": "Barcode",
"fieldname": "pos_barcode",
"placeholder": "Barcode / Serial No"
},
parent: this.wrapper.find(".barcode-area"),
only_input: true,
});
this.barcode.make_input();
this.barcode.$input.on("keypress", function() {
if(me.barcode_timeout)
clearTimeout(me.barcode_timeout);
me.barcode_timeout = setTimeout(function() { me.add_item_thru_barcode(); }, 1000);
});
},
make_search: function() { make_search: function() {
var me = this; var me = this;
this.search = frappe.ui.form.make_control({ this.search = frappe.ui.form.make_control({
@ -114,25 +91,6 @@ erpnext.POS = Class.extend({
me.item_timeout = setTimeout(function() { me.make_item_list(); }, 1000); me.item_timeout = setTimeout(function() { me.make_item_list(); }, 1000);
}); });
}, },
make_item_group: function() {
var me = this;
this.item_group = frappe.ui.form.make_control({
df: {
"fieldtype": "Link",
"options": "Item Group",
"label": "Item Group",
"fieldname": "pos_item_group",
"placeholder": "Item Group"
},
parent: this.wrapper.find(".item-group-area"),
only_input: true,
});
this.item_group.make_input();
this.item_group.$input.on("change", function() {
if(!me.item_group.autocomplete_open)
me.make_item_list();
});
},
make_item_list: function() { make_item_list: function() {
var me = this; var me = this;
if(!this.price_list) { if(!this.price_list) {
@ -146,31 +104,32 @@ erpnext.POS = Class.extend({
args: { args: {
sales_or_purchase: this.sales_or_purchase, sales_or_purchase: this.sales_or_purchase,
price_list: this.price_list, price_list: this.price_list,
item_group: this.item_group.$input.val(),
item: this.search.$input.val() item: this.search.$input.val()
}, },
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();
if (r.message) { if (r.message) {
$.each(r.message, function(index, obj) { if (r.message.length === 1) {
if (obj.image) var item = r.message[0];
image = '<img src="' + obj.image + '" class="img-responsive" \ if (item.serial_no) {
style="border:1px solid #eee; max-height: 140px;">'; me.add_to_cart(item.item_code, item.serial_no);
else this.search.$input.val("");
image = '<div class="missing-image"><i class="octicon octicon-circle-slash"></i></div>'; return;
$(repl('<div class="col-xs-3 pos-item" data-item_code="%(item_code)s">\ } else if (item.barcode) {
<div style="height: 140px; overflow: hidden;">%(item_image)s</div>\ me.add_to_cart(item.item_code);
<div class="small">%(item_code)s</div>\ this.search.$input.val("");
<div class="small">%(item_name)s</div>\ return;
<div class="small">%(item_price)s</div>\ }
</div>', }
{
$.each(r.message, function(index, obj) {
$(frappe.render_template("pos_item", {
item_code: obj.name, item_code: obj.name,
item_price: format_currency(obj.price_list_rate, obj.currency), item_price: format_currency(obj.price_list_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: obj.image
})).appendTo($wrap); })).appendTo($wrap);
}); });
} }
@ -178,8 +137,7 @@ erpnext.POS = Class.extend({
// 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() {
if(me.frm.doc.docstatus==0) { if(me.frm.doc.docstatus==0) {
console.log($(this).attr("data-item_code")); me.add_to_cart($(this).attr("data-item-code"));
me.add_to_cart($(this).attr("data-item_code"));
} }
}); });
} }
@ -224,6 +182,7 @@ erpnext.POS = Class.extend({
var child = frappe.model.add_child(me.frm.doc, this.frm.doctype + " Item", "items"); var child = frappe.model.add_child(me.frm.doc, this.frm.doctype + " Item", "items");
child.item_code = item_code; child.item_code = item_code;
child.qty = 1;
if (serial_no) if (serial_no)
child.serial_no = serial_no; child.serial_no = serial_no;
@ -240,7 +199,6 @@ erpnext.POS = Class.extend({
} }
}, },
update_qty: function(item_code, qty) { update_qty: function(item_code, qty) {
console.log([item_code, qty]);
var me = this; var me = this;
$.each(this.frm.doc["items"] || [], function(i, d) { $.each(this.frm.doc["items"] || [], function(i, d) {
if (d.item_code == item_code) { if (d.item_code == item_code) {
@ -260,7 +218,6 @@ erpnext.POS = Class.extend({
this.refresh_item_list(); this.refresh_item_list();
this.party_field.set_input(this.frm.doc[this.party.toLowerCase()]); this.party_field.set_input(this.frm.doc[this.party.toLowerCase()]);
this.wrapper.find('input.discount-amount').val(this.frm.doc.discount_amount); this.wrapper.find('input.discount-amount').val(this.frm.doc.discount_amount);
this.barcode.set_input("");
this.show_items_in_item_cart(); this.show_items_in_item_cart();
this.show_taxes(); this.show_taxes();
@ -294,9 +251,8 @@ erpnext.POS = Class.extend({
$.each(this.frm.doc.items|| [], function(i, d) { $.each(this.frm.doc.items|| [], function(i, d) {
$(frappe.render_template("pos_bill_item", { $(frappe.render_template("pos_bill_item", {
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 || !d.item_name) ? "" : ("<br>" + d.item_name),
qty: d.qty, qty: d.qty,
actual_qty: d.actual_qty,
rate: format_currency(d.rate, me.frm.doc.currency), rate: format_currency(d.rate, me.frm.doc.currency),
amount: format_currency(d.amount, me.frm.doc.currency) amount: format_currency(d.amount, me.frm.doc.currency)
})).appendTo($items); })).appendTo($items);
@ -309,21 +265,17 @@ erpnext.POS = Class.extend({
show_taxes: function() { show_taxes: function() {
var me = this; var me = this;
var taxes = this.frm.doc["taxes"] || []; var taxes = this.frm.doc["taxes"] || [];
$(this.wrapper).find(".tax-table") $(this.wrapper)
.toggle((taxes && taxes.length) ? true : false) .find(".tax-area").toggleClass("hide", (taxes && taxes.length) ? false : true)
.find("tbody").empty(); .find(".tax-table").empty();
$.each(taxes, function(i, d) { $.each(taxes, function(i, d) {
if (d.tax_amount) { if (d.tax_amount) {
$(repl('<tr>\ $(frappe.render_template("pos_tax_row", {
<td>%(description)s %(rate)s</td>\
<td style="text-align: right;">%(tax_amount)s</td>\
<tr>', {
description: d.description, description: d.description,
rate: ((d.charge_type == "Actual") ? '' : ("(" + d.rate + "%)")),
tax_amount: format_currency(flt(d.tax_amount)/flt(me.frm.doc.conversion_rate), tax_amount: format_currency(flt(d.tax_amount)/flt(me.frm.doc.conversion_rate),
me.frm.doc.currency) me.frm.doc.currency)
})).appendTo(".tax-table tbody"); })).appendTo(me.wrapper.find(".tax-table"));
} }
}); });
}, },
@ -345,7 +297,7 @@ erpnext.POS = Class.extend({
// append quantity to the respective item after change from input box // append quantity to the respective item after change from input box
$(this.wrapper).find("input.pos-item-qty").on("change", function() { $(this.wrapper).find("input.pos-item-qty").on("change", function() {
var item_code = $(this).closest("tr").attr("id"); var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
me.update_qty(item_code, $(this).val()); me.update_qty(item_code, $(this).val());
}); });
@ -374,7 +326,7 @@ erpnext.POS = Class.extend({
}, },
focus: function() { focus: function() {
if(me.frm.doc[this.party].toLowerCase()) { if(me.frm.doc[this.party].toLowerCase()) {
this.barcode.$input.focus(); this.search.$input.focus();
} else { } else {
if(!(this.frm.doctype == "Quotation" && this.frm.doc.quotation_to!="Customer")) if(!(this.frm.doctype == "Quotation" && this.frm.doc.quotation_to!="Customer"))
this.party_field.$input.focus(); this.party_field.$input.focus();
@ -393,39 +345,24 @@ erpnext.POS = Class.extend({
var me = this; 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
$(this.wrapper) $(this.wrapper)
.find(".remove-items, .make-payment, .pos-qty-btn") .find(".pos-qty-btn")
.toggle(this.frm.doc.docstatus===0); .toggle(this.frm.doc.docstatus===0);
$(this.wrapper).find('input, button').prop("disabled", !(this.frm.doc.docstatus===0)); $(this.wrapper).find('input, button').prop("disabled", !(this.frm.doc.docstatus===0));
this.wrapper.find(".pos-item-area").toggleClass("hide", me.frm.doc.docstatus!==0);
}, },
hide_payment_button: function() { hide_payment_button: function() {
var toggle = !(this.frm.doctype == "Sales Invoice" && this.frm.doc.is_pos && this.frm.doc.docstatus===1);
$(this.wrapper) $(this.wrapper)
.find(".make-payment") .find(".make-payment")
.toggle(this.frm.doctype == "Sales Invoice" && this.frm.doc.is_pos); .toggleClass("hide", toggle)
.prop("disabled", toggle);
}, },
refresh_delete_btn: function() { refresh_delete_btn: function() {
$(this.wrapper).find(".remove-items").toggle($(".item-cart .warning").length ? true : false); $(this.wrapper).find(".remove-items").toggle($(".item-cart .warning").length ? true : false);
}, },
add_item_thru_barcode: function() {
var me = this;
me.barcode_timeout = null;
frappe.call({
method: 'erpnext.accounts.doctype.sales_invoice.pos.get_item_code',
args: {barcode_serial_no: this.barcode.$input.val()},
callback: function(r) {
if (r.message) {
if (r.message[1] == "serial_no")
me.add_to_cart(r.message[0][0].item_code, r.message[0][0].name);
else
me.add_to_cart(r.message[0][0].name);
}
else
msgprint(__("Invalid Barcode"));
me.refresh();
}
});
},
remove_selected_items: function() { remove_selected_items: function() {
var me = this; var me = this;
var selected_items = []; var selected_items = [];
@ -457,7 +394,7 @@ erpnext.POS = Class.extend({
}, },
make_payment: function() { make_payment: function() {
var me = this; var me = this;
var no_of_items = $(this.wrapper).find("#cart tbody tr").length; var no_of_items = this.frm.doc.items.length;
var mode_of_payment = []; var mode_of_payment = [];
if (no_of_items == 0) if (no_of_items == 0)

View File

@ -1,11 +1,10 @@
<div class="row pos-bill-row pos-bill-item" data-item-code="{%= item_code %}"> <div class="row pos-bill-row pos-bill-item" data-item-code="{%= item_code %}">
<div class="col-xs-5"><h6>{%= item_code %}{%= item_name %}</h6></div> <div class="col-xs-5"><h6>{%= item_code || "" %}{%= item_name || "" %}</h6></div>
<div class="col-xs-4"> <div class="col-xs-4">
<div class="row pos-qty-row"> <div class="row pos-qty-row">
<div class="col-xs-2 text-center pos-qty-btn" data-action="decrease-qty"><i class="icon-minus-sign text-muted"></i></div> <div class="col-xs-2 text-center pos-qty-btn" data-action="decrease-qty"><i class="icon-minus-sign text-muted"></i></div>
<div class="col-xs-8"> <div class="col-xs-8">
<input type="text" value="{%= qty %}" class="form-control input-sm pos-item-qty text-right"> <input type="text" value="{%= qty %}" class="form-control input-sm pos-item-qty text-right">
<div class="actual-qty small text-muted text-right">{%= actual_qty %}</div>
</div> </div>
<div class="col-xs-2 text-center pos-qty-btn" data-action="increase-qty"><i class="icon-plus-sign text-muted"></i></div> <div class="col-xs-2 text-center pos-qty-btn" data-action="increase-qty"><i class="icon-plus-sign text-muted"></i></div>
</div> </div>

View File

@ -0,0 +1,10 @@
<div class="pos-item" data-item-code="{%= item_code %}">
<div class="pos-item-image {% if (!item_image) { %} no-image {% } %}"
style="{% if (item_image) { %} background-image: url({%= item_image %}) {% } %}">
</div>
<h6 class="item-code text-ellipsis">{%= item_code %}</h6>
<div class="small text-ellipsis">
{% if (item_name) { %}{%= item_name %}<br>{% } %}
{%= item_price %}
</div>
</div>

View File

@ -0,0 +1,4 @@
<div class="row">
<div class="col-xs-9">{%= description %}</div>
<div class="col-xs-3 text-right">{%= tax_amount %}</div>
</div>

View File

@ -154,7 +154,8 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
ignore_pricing_rule: me.frm.doc.ignore_pricing_rule, ignore_pricing_rule: me.frm.doc.ignore_pricing_rule,
doctype: item.doctype, doctype: item.doctype,
name: item.name, name: item.name,
project_name: item.project_name || me.frm.doc.project_name project_name: item.project_name || me.frm.doc.project_name,
qty: item.qty
} }
}, },

View File

@ -230,7 +230,7 @@ def create_feed_and_todo():
"""update activty feed and create todo for creation of item, customer, vendor""" """update activty feed and create todo for creation of item, customer, vendor"""
frappe.get_doc({ frappe.get_doc({
"doctype": "Feed", "doctype": "Feed",
"feedtype": "Comment", "feed_type": "Comment",
"subject": "ERPNext Setup Complete!" "subject": "ERPNext Setup Complete!"
}).insert(ignore_permissions=True) }).insert(ignore_permissions=True)

View File

@ -158,7 +158,7 @@ def get_basic_details(args, item):
"uom": item.stock_uom, "uom": item.stock_uom,
"min_order_qty": flt(item.min_order_qty) if args.parenttype == "Material Request" else "", "min_order_qty": flt(item.min_order_qty) if args.parenttype == "Material Request" else "",
"conversion_factor": 1.0, "conversion_factor": 1.0,
"qty": 0.0, "qty": args.qty or 0.0,
"stock_qty": 0.0, "stock_qty": 0.0,
"price_list_rate": 0.0, "price_list_rate": 0.0,
"base_price_list_rate": 0.0, "base_price_list_rate": 0.0,