[POS] enhancement and minor fixes

This commit is contained in:
Rohit Waghchaure 2016-05-20 23:55:45 +05:30
parent 1885645d6d
commit f2aa1764cc
10 changed files with 169 additions and 85 deletions

View File

@ -24,18 +24,6 @@ frappe.ui.form.on("POS Profile", "onload", function(frm) {
});
});
//cash bank account
//------------------------------------
cur_frm.fields_dict['cash_bank_account'].get_query = function(doc,cdt,cdn) {
return{
filters:{
'report_type': "Balance Sheet",
'is_group': 0,
'company': doc.company
}
}
}
// Income Account
// --------------------------------
cur_frm.fields_dict['income_account'].get_query = function(doc,cdt,cdn) {

View File

@ -739,33 +739,6 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "cash_bank_account",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Cash/Bank Account",
"length": 0,
"no_copy": 0,
"oldfieldname": "cash_bank_account",
"oldfieldtype": "Link",
"options": "Account",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@ -857,7 +830,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2016-05-09 00:00:30.610878",
"modified": "2016-05-25 15:00:09.335025",
"modified_by": "Administrator",
"module": "Accounts",
"name": "POS Profile",

View File

@ -27,7 +27,7 @@ class POSProfile(Document):
self.company), raise_exception=1)
def validate_all_link_fields(self):
accounts = {"Account": [self.cash_bank_account, self.income_account,
accounts = {"Account": [self.income_account,
self.expense_account], "Cost Center": [self.cost_center],
"Warehouse": [self.warehouse]}

View File

@ -7,6 +7,7 @@ from frappe import _
from frappe.utils import nowdate
from erpnext.setup.utils import get_exchange_rate
from erpnext.stock.get_item_details import get_pos_profile
from erpnext.accounts.party import get_party_account_currency
from erpnext.controllers.accounts_controller import get_taxes_and_charges
@frappe.whitelist()
@ -28,7 +29,7 @@ def get_pos_data():
return {
'doc': doc,
'items': get_items(doc, pos_profile),
'customers': get_customers(pos_profile),
'customers': get_customers(pos_profile, doc),
'pricing_rules': get_pricing_rules(doc),
'mode_of_payment': get_mode_of_payment(doc),
'print_template': print_template,
@ -68,6 +69,12 @@ def update_multi_mode_option(doc, pos_profile):
from frappe.model import default_fields
if not pos_profile:
for payment in frappe.get_all('Mode of Payment Account', fields=["default_account", "parent"],
filters = {'company': doc.company}):
payments = doc.append('payments', {})
payments.mode_of_payment = payment.parent
payments.account = payment.default_account
return
for payment_mode in pos_profile.payments:
@ -106,12 +113,19 @@ def get_items(doc, pos_profile):
return item_list
def get_customers(pos_profile):
def get_customers(pos_profile, doc):
filters = {'disabled': 0}
customer_list = []
if pos_profile.get('customer'):
filters.update({'name': pos_profile.customer})
return frappe.get_all("Customer", fields=["*"], filters = filters)
customers = frappe.get_all("Customer", fields=["*"], filters = filters)
for customer in customers:
customer_currency = get_party_account_currency('Customer', customer.name, doc.company) or doc.currency
if customer_currency == doc.currency:
customer_list.append(customer)
return customer_list
def get_pricing_rules(doc):
if doc.ignore_pricing_rule == 0:

View File

@ -525,7 +525,6 @@ class TestSalesInvoice(unittest.TestCase):
def make_pos_profile(self):
pos_profile = frappe.get_doc({
"cash_bank_account": "_Test Bank - _TC",
"company": "_Test Company",
"cost_center": "_Test Cost Center - _TC",
"currency": "INR",

View File

@ -4,7 +4,7 @@ frappe.provide("erpnext.pos");
frappe.pages['pos'].on_page_load = function(wrapper) {
var page = frappe.ui.make_app_page({
parent: wrapper,
title: 'Point of Sale',
title: __('Point of Sale'),
single_column: true
});
@ -32,6 +32,8 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
var me = this;
if(this.load){
this.load = false;
}else if(this.connection_status){
this.onload();
}else{
this.create_new();
}
@ -42,12 +44,13 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
//Check Internet connection after every 30 seconds
setInterval(function(){
me.set_indicator();
}, 30000)
}, 5000)
},
set_indicator: function(){
var me = this;
// navigator.onLine
this.connection_status = false;
this.page.set_indicator("Offline", "grey")
frappe.call({
method:"frappe.handler.ping",
@ -73,6 +76,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
var me = this;
this.page.add_menu_item(__("New Sales Invoice"), function() {
me.save_previous_entry()
me.create_new()
})
@ -89,7 +93,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
});
this.page.add_menu_item(__("POS Profile"), function() {
frappe.set_route('POS Profile');
frappe.set_route('List', 'POS Profile');
});
},
@ -106,8 +110,8 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
$(this.list_body).append('<div class="row list-row list-row-head pos-invoice-list">\
<div class="col-xs-3">Sr</div>\
<div class="col-xs-3">Customer</div>\
<div class="col-xs-3 text-right">Grand Total</div>\
<div class="col-xs-3 text-right">Status</div>\
<div class="col-xs-4 text-center">Grand Total</div>\
<div class="col-xs-2 text-left">Status</div>\
</div>')
$.each(this.si_docs, function(index, data){
@ -117,7 +121,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
name: key,
customer: data[key].customer,
grand_total: format_currency(data[key].grand_total, me.frm.doc.currency),
status: (data[key].docstatus == 1) ? 'Submitted' : 'Draft'
data: me.get_doctype_status(data[key])
})).appendTo($(me.list_body));
}
})
@ -135,6 +139,16 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
})
},
get_doctype_status: function(doc){
if(doc.outstanding_amount == 0){
return {status: "Paid", indicator: "green"}
}else if(doc.docstatus == 0){
return {status: "Draft", indicator: "red"}
}else if(doc.paid_amount >= 0){
return {status: "Unpaid", indicator: "orange"}
}
},
set_missing_values: function(){
var me = this;
doc = JSON.parse(localStorage.getItem('doc'))
@ -174,11 +188,16 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
})
},
save_previous_entry : function(){
if(this.frm.doc.items.length > 0){
this.create_invoice()
}
},
create_new: function(){
var me = this;
this.frm = {}
this.name = '';
this.frm.doc = JSON.parse(localStorage.getItem('doc'))
this.load_data();
this.setup();
},
@ -187,6 +206,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
this.items = window.items;
this.customers = window.customers;
this.pricing_rules = window.pricing_rules;
this.frm.doc = JSON.parse(localStorage.getItem('doc'));
$.each(window.meta, function(i, data){
frappe.meta.sync(data)
@ -264,6 +284,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
}
this.party_field.$input.autocomplete({
autoFocus: true,
source: function (request, response) {
me.customer_data = me.get_customers(request.term)
response($.map(me.customer_data, function(data){
@ -282,19 +303,30 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
}
me.refresh();
}
})
}).on("focus", function(){
setTimeout(function() {
if(!me.party_field.$input.val()) {
me.party_field.$input.autocomplete( "search", " " );
}
}, 500);
});
},
get_customers: function(key){
var me = this;
key = key.toLowerCase()
return $.grep(this.customers, function(data) {
if(data.name.toLowerCase().match(key)
|| data.customer_name.toLowerCase().match(key)
|| (data.customer_group && data.customer_group.toLowerCase().match(key))){
return data
}
})
key = key.toLowerCase().trim()
if(key){
return $.grep(this.customers, function(data) {
if(data.name.toLowerCase().match(key)
|| data.customer_name.toLowerCase().match(key)
|| (data.customer_group && data.customer_group.toLowerCase().match(key))){
return data
}
})
}else{
customers = this.customers.sort(function(a,b){ return a.idx < b.idx })
return customers.slice(0, 20)
}
},
make_item_list: function() {
@ -377,39 +409,52 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
$(this.wrapper).find(".pos-item-qty").on("change", function(){
var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
me.update_qty_against_item_code(item_code, $(this).val());
me.update_qty_rate_against_item_code(item_code, "qty", $(this).val());
})
$(this.wrapper).find("[data-action='increase-qty']").on("click", function(){
var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) + 1;
me.update_qty_against_item_code(item_code, qty);
me.update_qty_rate_against_item_code(item_code, "qty", qty);
})
$(this.wrapper).find("[data-action='decrease-qty']").on("click", function(){
var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) - 1;
me.update_qty_against_item_code(item_code, qty);
me.update_qty_rate_against_item_code(item_code, "qty", qty);
})
},
update_qty_against_item_code: function(item_code, qty){
update_rate: function() {
var me = this;
if(qty < 0){
frappe.throw(__("Quantity must be positive"));
$(this.wrapper).find(".pos-item-rate").on("change", function(){
var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
me.update_qty_rate_against_item_code(item_code, "rate", $(this).val());
})
},
update_qty_rate_against_item_code: function(item_code, field, value){
var me = this;
if(value < 0){
frappe.throw(__("Enter value must be positive"));
}
this.remove_item = []
$.each(this.frm.doc["items"] || [], function(i, d) {
if (d.item_code == item_code) {
d.qty = flt(qty);
d[field] = flt(value);
d.amount = flt(d.rate) * flt(d.qty);
if(d.qty==0){
me.remove_item.push(d.idx)
}
}
});
this.remove_zero_qty_item();
if(field == 'qty'){
this.remove_zero_qty_item();
}
this.refresh();
},
@ -512,6 +557,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
var me = this;
this.refresh_fields();
this.update_qty();
this.update_rate();
this.set_primary_action();
},
refresh_fields: function() {
@ -544,7 +590,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
qty: d.qty,
actual_qty: d.actual_qty,
projected_qty: d.projected_qty,
rate: format_currency(d.rate, me.frm.doc.currency),
rate: format_number(d.rate, me.frm.doc.currency),
amount: format_currency(d.amount, me.frm.doc.currency)
})).appendTo($items);
});
@ -552,6 +598,10 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
this.wrapper.find("input.pos-item-qty").on("focus", function() {
$(this).select();
});
this.wrapper.find("input.pos-item-rate").on("focus", function() {
$(this).select();
});
},
set_taxes: function(){
@ -596,18 +646,23 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
}else if(this.frm.doc.docstatus == 1){
this.page.set_primary_action(__("Print"), function() {
html = frappe.render(me.print_template, me.frm.doc)
frappe.require("/assets/js/print_format_v3.min.js", function() {
w = _p.preview(html);
setTimeout(function(){
w.print();
}, 1000)
});
me.print_document(html)
})
}else {
this.page.clear_primary_action()
}
},
print_document: function(html){
var w = window.open();
w.document.write(html);
w.document.close();
setTimeout(function(){
w.print();
w.close();
}, 1000)
},
write_off_amount: function(){
var me = this;
var value = 0.0;
@ -723,7 +778,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
var me = this;
this.si_docs = this.get_submitted_invoice()
if(this.connection_status && this.si_docs.length){
if(this.si_docs.length){
frappe.call({
method: "erpnext.accounts.doctype.sales_invoice.pos.make_invoice",
args: {
@ -740,12 +795,14 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
},
get_submitted_invoice: function(){
invoices = []
docs = this.get_doc_from_localstorage()
var invoices = [];
var index = 1;
docs = this.get_doc_from_localstorage();
if(docs){
invoices = $.map(docs, function(data){
for(key in data){
if(data[key].docstatus == 1){
if(data[key].docstatus == 1 && index < 50){
index++
return data
}
}

View File

@ -6,9 +6,9 @@
"docstatus": 0,
"doctype": "Print Format",
"font": "Default",
"html": "<style>\n\t.print-format table, .print-format tr, \n\t.print-format td, .print-format div, .print-format p {\n\t\tfont-family: Monospace;\n\t\tline-height: 200%;\n\t\tvertical-align: middle;\n\t}\n\t@media screen {\n\t\t.print-format {\n\t\t\twidth: 4in;\n\t\t\tpadding: 0.25in;\n\t\t\tmin-height: 8in;\n\t\t}\n\t}\n</style>\n\n<p class=\"text-center\">\n\t{{ company }}<br>\n\t{{ __(\"Invoice\") }}<br>\n</p>\n<p>\n\t<b>{{ __(\"Date\") }}:</b> {{ posting_date }}<br>\n</p>\n\n<hr>\n<table class=\"table table-condensed cart no-border\">\n\t<thead>\n\t\t<tr>\n\t\t\t<th width=\"50%\">{{ __(\"Item\") }}</b></th>\n\t\t\t<th width=\"25%\" class=\"text-right\">{{ __(\"Qty\") }}</th>\n\t\t\t<th width=\"25%\" class=\"text-right\">{{ __(\"Amount\") }}</th>\n\t\t</tr>\n\t</thead>\n\t<tbody>\n\t\t{% for item in items %}\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t{{ item.item_name }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">{{ item.qty }}<br>@ {{ format_currency(item.rate, currency) }}</td>\n\t\t\t<td class=\"text-right\">{{ format_currency(item.amount, currency) }}</td>\n\t\t</tr>\n\t\t{% endfor %}\n\t</tbody>\n</table>\n\n<table class=\"table table-condensed no-border\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 70%\">\n\t\t\t\t{{ __(\"Net Total\") }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(total, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% for row in taxes %}\n\t\t{% if not row.included_in_print_rate %}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 70%\">\n\t\t\t\t{{ row.description }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(row.tax_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% endif %}\n\t\t{% endfor %}\n\t\t{% if discount_amount %}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t{{ __(\"Discount\") }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(discount_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% endif %}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t<b>{{ __(\"Grand Total\") }}</b>\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(grand_total, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n\n\n<hr>\n<p class=\"text-center\">{{ __(\"Thank you, please visit again.\") }}</p>",
"html": "<style>\n\t.print-format table, .print-format tr, \n\t.print-format td, .print-format div, .print-format p {\n\t\tfont-family: Monospace;\n\t\tline-height: 200%;\n\t\tvertical-align: middle;\n\t}\n\t@media screen {\n\t\t.print-format {\n\t\t\twidth: 4in;\n\t\t\tpadding: 0.25in;\n\t\t\tmin-height: 8in;\n\t\t}\n\t}\n</style>\n\n<p class=\"text-center\">\n\t{{ company }}<br>\n\t{{ __(\"Invoice\") }}<br>\n</p>\n<p>\n\t<b>{{ __(\"Date\") }}:</b> {{ dateutil.global_date_format(posting_date) }}<br>\n</p>\n\n<hr>\n<table class=\"table table-condensed cart no-border\">\n\t<thead>\n\t\t<tr>\n\t\t\t<th width=\"50%\">{{ __(\"Item\") }}</b></th>\n\t\t\t<th width=\"25%\" class=\"text-right\">{{ __(\"Qty\") }}</th>\n\t\t\t<th width=\"25%\" class=\"text-right\">{{ __(\"Amount\") }}</th>\n\t\t</tr>\n\t</thead>\n\t<tbody>\n\t\t{% for item in items %}\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t{{ item.item_name }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">{{ item.qty }}<br>@ {{ format_currency(item.rate, currency) }}</td>\n\t\t\t<td class=\"text-right\">{{ format_currency(item.amount, currency) }}</td>\n\t\t</tr>\n\t\t{% endfor %}\n\t</tbody>\n</table>\n\n<table class=\"table table-condensed no-border\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 70%\">\n\t\t\t\t{{ __(\"Net Total\") }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(total, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% for row in taxes %}\n\t\t{% if not row.included_in_print_rate %}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 70%\">\n\t\t\t\t{{ row.description }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(row.tax_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% endif %}\n\t\t{% endfor %}\n\t\t{% if discount_amount %}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t{{ __(\"Discount\") }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(discount_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% endif %}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t<b>{{ __(\"Grand Total\") }}</b>\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(grand_total, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n\n\n<hr>\n<p class=\"text-center\">{{ __(\"Thank you, please visit again.\") }}</p>",
"idx": 0,
"modified": "2016-05-11 15:04:24.359583",
"modified": "2016-05-21 00:25:20.359074",
"modified_by": "Administrator",
"name": "Point of Sale",
"owner": "Administrator",

View File

@ -17,6 +17,7 @@
</div>
</div>
<div class="col-xs-3 text-right">
<h6>{%= amount %}<div class="text-muted" style="margin-top: 5px;">{%= rate %}</div></h6>
<div class="text-muted" style="margin-top: 5px;"><input type="text" value="{%= rate %}" class="form-control input-sm pos-item-rate text-right"></div>
<p><h6>{%= amount %}</h6></p>
</div>
</div>

View File

@ -1,6 +1,6 @@
<div class="row list-row pos-invoice-list" invoice-name = "{{name}}">
<div class="col-xs-3">{%= sr %}</div>
<div class="col-xs-3">{%= customer %}</div>
<div class="col-xs-3 text-right">{%= grand_total %}</div>
<div class="col-xs-3 text-right">{%= status %}</div>
<div class="col-xs-4 text-center">{%= grand_total %}</div>
<div class="col-xs-2 text-left"><span class="indicator {{data.indicator}}">{{ data.status }}</span></div>
</div>

View File

@ -156,3 +156,55 @@
.dashboard-list-item:last-child {
border-bottom: none;
}
.payment-toolbar {
margin-left: 35px;
}
.payment-mode {
cursor: pointer;
font-family: sans-serif;
font-size: 15px;
}
.pos-payment-row .col-xs-6 {
padding :10px;
}
.pos-payment-row {
border-bottom:1px solid #d1d8dd;
margin: 2px 0px 5px 0px;
}
.pos-payment-row:hover, .pos-keyboard-key:hover{
background-color: #FAFBFC;
cursor: pointer;
}
.pos-keyboard-key, .delete-btn {
border: 1px solid #d1d8dd;
height:85px;
width:85px;
margin:10px 10px;
font-size:24px;
font-weight:200;
background-color: #FDFDFD;
border-color: #e8e8e8;
}
.amount {
margin-top: 5px;
}
.amount-label {
font-size: 16px;
}
.selected-payment-mode {
background-color: #FAFBFC;
cursor: pointer;
}
.pos-invoice-list {
padding: 15px 10px;
}