[pos] pos.js included in all selling & purchase cycle

This commit is contained in:
Akhilesh Darjee 2013-09-18 18:35:12 +05:30
parent a550e7443f
commit f83576bf9c
12 changed files with 78 additions and 50 deletions

View File

@ -8,6 +8,7 @@ cur_frm.cscript.other_fname = "purchase_tax_details";
wn.provide("erpnext.accounts"); wn.provide("erpnext.accounts");
wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js'); wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
wn.require('app/buying/doctype/purchase_common/purchase_common.js'); wn.require('app/buying/doctype/purchase_common/purchase_common.js');
wn.require('app/accounts/doctype/sales_invoice/pos.js');
erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
onload: function() { onload: function() {

View File

@ -7,7 +7,7 @@ erpnext.POS = Class.extend({
this.frm = frm; this.frm = frm;
this.wrapper.html('<div class="container">\ this.wrapper.html('<div class="container">\
<div class="row">\ <div class="row">\
<div class="customer-area col-sm-3 col-xs-6"></div>\ <div class="party-area col-sm-3 col-xs-6"></div>\
<div class="barcode-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="search-area col-sm-3 col-xs-6"></div>\
<div class="item-group-area col-sm-3 col-xs-6"></div>\ <div class="item-group-area col-sm-3 col-xs-6"></div>\
@ -88,29 +88,31 @@ erpnext.POS = Class.extend({
}); });
}, },
make: function() { make: function() {
this.make_customer(); this.make_party();
this.make_item_group(); this.make_item_group();
this.make_search(); this.make_search();
this.make_barcode(); this.make_barcode();
this.make_item_list(); this.make_item_list();
}, },
make_customer: function() { make_party: function() {
var me = this; var me = this;
console.log(this.frm); this.party = wn.meta.has_field(cur_frm.doc.doctype, "customer") ?"Customer" : "Supplier";
this.customer = wn.ui.form.make_control({
this.party_field = wn.ui.form.make_control({
df: { df: {
"fieldtype": "Link", "fieldtype": "Link",
"options": "Customer", "options": this.party,
"label": "Customer", "label": this.party,
"fieldname": "pos_customer", "fieldname": "pos_party",
"placeholder": "Customer" "placeholder": this.party
}, },
parent: this.wrapper.find(".customer-area") parent: this.wrapper.find(".party-area")
}); });
this.customer.make_input(); this.party_field.make_input();
this.customer.$input.on("change", function() { this.party_field.$input.on("change", function() {
if(!me.customer.autocomplete_open) if(!me.party_field.autocomplete_open)
wn.model.set_value(this.frm.doctype, me.frm.docname, "customer", this.value); wn.model.set_value(me.frm.doctype, me.frm.docname,
me.party.toLowerCase(), this.value);
}); });
}, },
make_item_group: function() { make_item_group: function() {
@ -169,10 +171,17 @@ erpnext.POS = Class.extend({
}, },
make_item_list: function() { make_item_list: function() {
var me = this; var me = this;
var price_list = wn.meta.has_field(this.frm.doc.doctype, "selling_price_list") ?
this.frm.doc.selling_price_list : this.frm.doc.buying_price_list;
var sales_or_purchase = wn.meta.has_field(this.frm.doc.doctype, "selling_price_list") ?
"Sales" : "Purchase";
wn.call({ wn.call({
method: 'accounts.doctype.sales_invoice.pos.get_items', method: 'accounts.doctype.sales_invoice.pos.get_items',
args: { args: {
price_list: cur_frm.doc.selling_price_list, sales_or_purchase: sales_or_purchase,
price_list: price_list,
item_group: this.item_group.$input.val(), item_group: this.item_group.$input.val(),
item: this.search.$input.val() item: this.search.$input.val()
}, },
@ -203,8 +212,8 @@ erpnext.POS = Class.extend({
// if form is local then allow this function // if form is local then allow this function
if (cur_frm.doc.docstatus===0) { if (cur_frm.doc.docstatus===0) {
$("div.pos-item").on("click", function() { $("div.pos-item").on("click", function() {
if(!cur_frm.doc.customer) { if(!cur_frm.doc[me.party.toLowerCase()]) {
msgprint("Please select customer first."); msgprint("Please select " + me.party + " first.");
return; return;
} }
me.add_to_cart($(this).attr("data-item_code")); me.add_to_cart($(this).attr("data-item_code"));
@ -222,8 +231,8 @@ erpnext.POS = Class.extend({
// check whether the item is already added // check whether the item is already added
if (no_of_items != 0) { if (no_of_items != 0) {
$.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name, "entries", $.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name,
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)
caught = true; caught = true;
}); });
@ -234,15 +243,16 @@ erpnext.POS = Class.extend({
me.update_qty(item_code, 1); me.update_qty(item_code, 1);
} }
else { else {
var child = wn.model.add_child(me.frm.doc, this.frm.doctype + " Item", "entries"); var child = wn.model.add_child(me.frm.doc, this.frm.doctype + " Item",
this.frm.cscript.fname);
child.item_code = item_code; child.item_code = item_code;
me.frm.cscript.item_code(me.frm.doc, child.doctype, child.name); me.frm.cscript.item_code(me.frm.doc, child.doctype, child.name);
} }
}, },
update_qty: function(item_code, qty, textbox_qty) { update_qty: function(item_code, qty, textbox_qty) {
var me = this; var me = this;
$.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name, "entries", $.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name,
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 (textbox_qty) { if (textbox_qty) {
if (qty == 0 && d.item_code == item_code) if (qty == 0 && d.item_code == item_code)
@ -260,14 +270,14 @@ erpnext.POS = Class.extend({
}, },
refresh: function() { refresh: function() {
var me = this; var me = this;
this.customer.set_input(this.frm.doc.customer); this.party_field.set_input(this.frm.doc[this.party.toLowerCase()]);
this.barcode.set_input(""); this.barcode.set_input("");
// add items // add items
var $items = me.wrapper.find("#cart tbody").empty(); var $items = me.wrapper.find("#cart tbody").empty();
$.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name, "entries", $.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name,
this.frm.doctype), function(i, d) { this.frm.cscript.fname, this.frm.doctype), function(i, d) {
$(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" \
@ -379,17 +389,16 @@ erpnext.POS = Class.extend({
} }
} }
var child = wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name, "entries", var child = wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name,
this.frm.doctype); this.frm.cscript.fname, this.frm.doctype);
$.each(child, function(i, d) { $.each(child, function(i, d) {
for (var i in selected_items) { for (var i in selected_items) {
if (d.item_code == selected_items[i]) { if (d.item_code == selected_items[i]) {
// cur_frm.fields_dict["entries"].grid.grid_rows[d.idx].remove();
wn.model.clear_doc(d.doctype, d.name); wn.model.clear_doc(d.doctype, d.name);
} }
} }
}); });
cur_frm.fields_dict["entries"].grid.refresh(); cur_frm.fields_dict[this.frm.cscript.fname].grid.refresh();
cur_frm.script_manager.trigger("calculate_taxes_and_totals"); cur_frm.script_manager.trigger("calculate_taxes_and_totals");
me.frm.dirty(); me.frm.dirty();
me.refresh(); me.refresh();

View File

@ -3,17 +3,22 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes import msgprint from webnotes import msgprint, errprint
@webnotes.whitelist() @webnotes.whitelist()
def get_items(price_list, item=None, item_group=None): def get_items(price_list, sales_or_purchase, item=None, item_group=None):
condition = "" condition = ""
if sales_or_purchase == "Sales":
condition = "i.is_sales_item='Yes'"
else:
condition = "i.is_purchase_item='Yes'"
if item_group and item_group != "All Item Groups": if item_group and item_group != "All Item Groups":
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 i.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,
pl_items.ref_rate, pl_items.currency pl_items.ref_rate, pl_items.currency
@ -24,7 +29,7 @@ def get_items(price_list, item=None, item_group=None):
ON ON
pl_items.item_code=i.name pl_items.item_code=i.name
where where
i.is_sales_item='Yes'%s""" % ('%s', condition), (price_list), as_dict=1) %s""" % ('%s', condition), (price_list), as_dict=1)
@webnotes.whitelist() @webnotes.whitelist()
def get_item_from_barcode(barcode): def get_item_from_barcode(barcode):

View File

@ -1,15 +0,0 @@
.pos-item {
height: 200px;
overflow: hidden;
cursor: pointer;
padding-left: 5px !important;
padding-right: 5px !important;
}
.pos-bill {
padding: 20px 5px;
font-family: Monospace;
border: 1px solid #eee;
-webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
}

View File

@ -78,6 +78,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
cur_frm.add_custom_button('Make Payment Entry', cur_frm.cscript.make_bank_voucher); cur_frm.add_custom_button('Make Payment Entry', cur_frm.cscript.make_bank_voucher);
} }
// Show buttons only when pos view is active
if (doc.docstatus===0 && !this.pos_active) { if (doc.docstatus===0 && !this.pos_active) {
cur_frm.cscript.sales_order_btn(); cur_frm.cscript.sales_order_btn();
cur_frm.cscript.delivery_note_btn(); cur_frm.cscript.delivery_note_btn();

View File

@ -10,6 +10,7 @@ cur_frm.cscript.other_fname = "purchase_tax_details";
wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js'); wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/buying/doctype/purchase_common/purchase_common.js'); wn.require('app/buying/doctype/purchase_common/purchase_common.js');
wn.require('app/accounts/doctype/sales_invoice/pos.js');
erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({
refresh: function(doc, cdt, cdn) { refresh: function(doc, cdt, cdn) {

View File

@ -9,6 +9,7 @@ cur_frm.cscript.other_fname = "purchase_tax_details";
// attach required files // attach required files
wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js'); wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
wn.require('app/buying/doctype/purchase_common/purchase_common.js'); wn.require('app/buying/doctype/purchase_common/purchase_common.js');
wn.require('app/accounts/doctype/sales_invoice/pos.js');
erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.extend({ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.extend({
refresh: function() { refresh: function() {

View File

@ -29,4 +29,21 @@ span, div, td, input, textarea, button, select {
width: 32px; width: 32px;
height: 32px; height: 32px;
margin: -10px auto; margin: -10px auto;
}
/* pos */
.pos-item {
height: 200px;
overflow: hidden;
cursor: pointer;
padding-left: 5px !important;
padding-right: 5px !important;
}
.pos-bill {
padding: 20px 5px;
font-family: Monospace;
border: 1px solid #eee;
-webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
} }

View File

@ -88,7 +88,11 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
}, },
toggle_pos: function(show) { toggle_pos: function(show) {
if (!this.frm.doc.selling_price_list) // Check whether it is Selling or Buying cycle
var price_list = wn.meta.has_field(cur_frm.doc.doctype, "selling_price_list") ?
this.frm.doc.selling_price_list : this.frm.doc.buying_price_list;
if (!price_list)
msgprint(wn._("Please select Price List")) msgprint(wn._("Please select Price List"))
else { else {
if((show===true && this.pos_active) || (show===false && !this.pos_active)) return; if((show===true && this.pos_active) || (show===false && !this.pos_active)) return;
@ -106,6 +110,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
// refresh // refresh
if(this.pos_active) if(this.pos_active)
this.frm.pos.refresh(); this.frm.pos.refresh();
this.frm.refresh();
} }
}, },

View File

@ -11,6 +11,7 @@ cur_frm.cscript.sales_team_fname = "sales_team";
wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js'); wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/selling/doctype/sales_common/sales_common.js'); wn.require('app/selling/doctype/sales_common/sales_common.js');
wn.require('app/accounts/doctype/sales_invoice/pos.js');
erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
onload: function(doc, dt, dn) { onload: function(doc, dt, dn) {

View File

@ -10,6 +10,7 @@ cur_frm.cscript.sales_team_fname = "sales_team";
wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js'); wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/selling/doctype/sales_common/sales_common.js'); wn.require('app/selling/doctype/sales_common/sales_common.js');
wn.require('app/accounts/doctype/sales_invoice/pos.js');
wn.provide("erpnext.stock"); wn.provide("erpnext.stock");
erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend({ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend({

View File

@ -8,6 +8,7 @@ cur_frm.cscript.other_fname = "purchase_tax_details";
wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js'); wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/buying/doctype/purchase_common/purchase_common.js'); wn.require('app/buying/doctype/purchase_common/purchase_common.js');
wn.require('app/accounts/doctype/sales_invoice/pos.js');
wn.provide("erpnext.stock"); wn.provide("erpnext.stock");
erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend({ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend({