[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
@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 = ""
args = {"price_list": price_list}
@ -14,10 +14,21 @@ def get_items(price_list, sales_or_purchase, item=None, item_group=None):
else:
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:
# 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"
args["name"] = "%%%s%%" % item
@ -31,21 +42,21 @@ def get_items(price_list, sales_or_purchase, item=None, item_group=None):
where
%s""" % ('%(price_list)s', condition), args, as_dict=1)
@frappe.whitelist()
def get_item_code(barcode_serial_no):
input_via = "serial_no"
item_code = frappe.db.sql("""select name, item_code from `tabSerial No` where
name=%s""", (barcode_serial_no), as_dict=1)
if not item_code:
input_via = "barcode"
item_code = frappe.db.sql("""select name from `tabItem` where barcode=%s""",
(barcode_serial_no), as_dict=1)
if item_code:
return item_code, input_via
else:
frappe.throw(frappe._("Invalid Barcode or Serial No"))
# @frappe.whitelist()
# def get_item_code(barcode_serial_no):
# input_via = "serial_no"
# item_code = frappe.db.sql("""select name, item_code from `tabSerial No` where
# name=%s""", (barcode_serial_no), as_dict=1)
#
# if not item_code:
# input_via = "barcode"
# item_code = frappe.db.sql("""select name from `tabItem` where barcode=%s""",
# (barcode_serial_no), as_dict=1)
#
# if item_code:
# return item_code, input_via
# else:
# frappe.throw(frappe._("Invalid Barcode or Serial No"))
@frappe.whitelist()
def get_mode_of_payment():

View File

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

View File

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

View File

@ -16,6 +16,8 @@
"public/js/templates/contact_list.html",
"public/js/pos/pos.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"
],
"css/shopping-cart-web.css": [

View File

@ -20,11 +20,32 @@
}
.pos-item {
height: 200px;
display: inline-block;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
padding-left: 5px !important;
padding-right: 5px !important;
padding: 10px;
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 {
@ -38,7 +59,7 @@
}
.item-list-area {
padding: 15px;
padding: 15px 0px;
}
.pos-toolbar, .pos-bill-toolbar {
@ -54,7 +75,7 @@
.pos-bill-wrapper {
border: 1px solid #d1d8dd;
border-top: none;
border-right: none;
margin-right: -1px;
}
.pos-bill {
@ -82,7 +103,15 @@
}
.pos-qty-btn {
margin-top: 5px;
margin-top: 3px;
cursor: pointer;
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="col-sm-5 pos-bill-wrapper">
<div class="pos-bill-toolbar row">
<div class="party-area col-xs-6"></div>
<div class="col-xs-6">
<button class="btn btn-success make-payment">{%= __("Pay") %}</button>
<div class="party-area col-xs-9"></div>
<div class="col-xs-3 text-right">
<button class="btn btn-success make-payment hide">{%= __("Pay") %}</button>
</div>
</div>
<div class="pos-bill">
@ -17,12 +17,15 @@
<div class="items"></div>
</div>
<div class="totals-area">
<div class="row pos-bill-row net-total-area">
<div class="row pos-bill-row net-total-area">
<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>
<div class="tax-table hide">
<h6>{%= __("Taxes") %}</h6>
<div class="row pos-bill-row tax-area hide">
<div class="col-xs-12 text-muted">
<h6>{%= __("Taxes") %}</h6>
<div class="tax-table small"></div>
</div>
</div>
<div class="row pos-bill-row discount-amount-area">
<div class="col-xs-6"><h6 class="text-muted">{%= __("Discount Amount") %}</h6></div>
@ -41,14 +44,10 @@
</div>
<div class="col-sm-7 pos-item-area">
<div class="row pos-item-toolbar">
<div class="barcode-area col-xs-4"></div>
<div class="search-area col-xs-4"></div>
<div class="item-group-area col-xs-4"></div>
<div class="search-area col-xs-12"></div>
</div>
<div class="item-list-area row">
<div class="col-sm-12">
<div class="row item-list"></div>
</div>
<div class="item-list-area">
<div class="item-list"></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);
});
this.call_function("remove-items", function() {me.remove_selected_items();});
this.call_function("make-payment", function() {me.make_payment();});
this.wrapper.find(".make-payment").on("click", function() {
me.make_payment();
})
},
check_transaction_type: function() {
var me = this;
@ -45,14 +46,9 @@ erpnext.POS = Class.extend({
// 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() {
this.make_party();
this.make_barcode();
this.make_search();
this.make_item_group();
this.make_item_list();
},
make_party: function() {
@ -75,25 +71,6 @@ erpnext.POS = Class.extend({
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() {
var me = this;
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);
});
},
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() {
var me = this;
if(!this.price_list) {
@ -146,40 +104,40 @@ erpnext.POS = Class.extend({
args: {
sales_or_purchase: this.sales_or_purchase,
price_list: this.price_list,
item_group: this.item_group.$input.val(),
item: this.search.$input.val()
},
callback: function(r) {
var $wrap = me.wrapper.find(".item-list");
me.wrapper.find(".item-list").empty();
if (r.message) {
$.each(r.message, function(index, obj) {
if (obj.image)
image = '<img src="' + obj.image + '" class="img-responsive" \
style="border:1px solid #eee; max-height: 140px;">';
else
image = '<div class="missing-image"><i class="octicon octicon-circle-slash"></i></div>';
if (r.message.length === 1) {
var item = r.message[0];
if (item.serial_no) {
me.add_to_cart(item.item_code, item.serial_no);
this.search.$input.val("");
return;
$(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 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.price_list_rate, obj.currency),
item_name: obj.name===obj.item_name ? "" : obj.item_name,
item_image: image
})).appendTo($wrap);
} else if (item.barcode) {
me.add_to_cart(item.item_code);
this.search.$input.val("");
return;
}
}
$.each(r.message, function(index, obj) {
$(frappe.render_template("pos_item", {
item_code: obj.name,
item_price: format_currency(obj.price_list_rate, obj.currency),
item_name: obj.name===obj.item_name ? "" : obj.item_name,
item_image: obj.image
})).appendTo($wrap);
});
}
// if form is local then allow this function
$(me.wrapper).find("div.pos-item").on("click", function() {
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");
child.item_code = item_code;
child.qty = 1;
if (serial_no)
child.serial_no = serial_no;
@ -240,7 +199,6 @@ erpnext.POS = Class.extend({
}
},
update_qty: function(item_code, qty) {
console.log([item_code, qty]);
var me = this;
$.each(this.frm.doc["items"] || [], function(i, d) {
if (d.item_code == item_code) {
@ -260,7 +218,6 @@ erpnext.POS = Class.extend({
this.refresh_item_list();
this.party_field.set_input(this.frm.doc[this.party.toLowerCase()]);
this.wrapper.find('input.discount-amount').val(this.frm.doc.discount_amount);
this.barcode.set_input("");
this.show_items_in_item_cart();
this.show_taxes();
@ -294,9 +251,8 @@ erpnext.POS = Class.extend({
$.each(this.frm.doc.items|| [], function(i, d) {
$(frappe.render_template("pos_bill_item", {
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,
actual_qty: d.actual_qty,
rate: format_currency(d.rate, me.frm.doc.currency),
amount: format_currency(d.amount, me.frm.doc.currency)
})).appendTo($items);
@ -309,21 +265,17 @@ erpnext.POS = Class.extend({
show_taxes: function() {
var me = this;
var taxes = this.frm.doc["taxes"] || [];
$(this.wrapper).find(".tax-table")
.toggle((taxes && taxes.length) ? true : false)
.find("tbody").empty();
$(this.wrapper)
.find(".tax-area").toggleClass("hide", (taxes && taxes.length) ? false : true)
.find(".tax-table").empty();
$.each(taxes, function(i, d) {
if (d.tax_amount) {
$(repl('<tr>\
<td>%(description)s %(rate)s</td>\
<td style="text-align: right;">%(tax_amount)s</td>\
<tr>', {
$(frappe.render_template("pos_tax_row", {
description: d.description,
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");
})).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
$(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());
});
@ -374,7 +326,7 @@ erpnext.POS = Class.extend({
},
focus: function() {
if(me.frm.doc[this.party].toLowerCase()) {
this.barcode.$input.focus();
this.search.$input.focus();
} else {
if(!(this.frm.doctype == "Quotation" && this.frm.doc.quotation_to!="Customer"))
this.party_field.$input.focus();
@ -393,39 +345,24 @@ erpnext.POS = Class.extend({
var me = this;
// if form is submitted & cancelled then disable all input box & buttons
$(this.wrapper)
.find(".remove-items, .make-payment, .pos-qty-btn")
.find(".pos-qty-btn")
.toggle(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() {
var toggle = !(this.frm.doctype == "Sales Invoice" && this.frm.doc.is_pos && this.frm.doc.docstatus===1);
$(this.wrapper)
.find(".make-payment")
.toggle(this.frm.doctype == "Sales Invoice" && this.frm.doc.is_pos);
.toggleClass("hide", toggle)
.prop("disabled", toggle);
},
refresh_delete_btn: function() {
$(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() {
var me = this;
var selected_items = [];
@ -457,7 +394,7 @@ erpnext.POS = Class.extend({
},
make_payment: function() {
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 = [];
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="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="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-8">
<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 class="col-xs-2 text-center pos-qty-btn" data-action="increase-qty"><i class="icon-plus-sign text-muted"></i></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,
doctype: item.doctype,
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"""
frappe.get_doc({
"doctype": "Feed",
"feedtype": "Comment",
"feed_type": "Comment",
"subject": "ERPNext Setup Complete!"
}).insert(ignore_permissions=True)

View File

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