[pos] pos view fixed for all purchase & sales cycle

This commit is contained in:
Akhilesh Darjee 2013-09-25 11:09:33 +05:30
parent dd68de824d
commit 10dce341c8
8 changed files with 83 additions and 31 deletions

View File

@ -62,19 +62,20 @@ class DocType(BuyingController):
"purchase_receipt_details")
def get_credit_to(self):
acc_head = sql("""select name, credit_days from `tabAccount`
where (name = %s or (master_name = %s and master_type = 'supplier'))
and docstatus != 2 and company = %s""",
(cstr(self.doc.supplier) + " - " + self.company_abbr,
self.doc.supplier, self.doc.company))
ret = {}
if acc_head and acc_head[0][0]:
ret['credit_to'] = acc_head[0][0]
if not self.doc.due_date:
ret['due_date'] = add_days(cstr(self.doc.posting_date), acc_head and cint(acc_head[0][1]) or 0)
elif not acc_head:
msgprint("%s does not have an Account Head in %s. You must first create it from the Supplier Master" % (self.doc.supplier, self.doc.company))
if self.doc.supplier:
acc_head = sql("""select name, credit_days from `tabAccount`
where (name = %s or (master_name = %s and master_type = 'supplier'))
and docstatus != 2 and company = %s""",
(cstr(self.doc.supplier) + " - " + self.company_abbr,
self.doc.supplier, self.doc.company))
if acc_head and acc_head[0][0]:
ret['credit_to'] = acc_head[0][0]
if not self.doc.due_date:
ret['due_date'] = add_days(cstr(self.doc.posting_date), acc_head and cint(acc_head[0][1]) or 0)
elif not acc_head:
msgprint("%s does not have an Account Head in %s. You must first create it from the Supplier Master" % (self.doc.supplier, self.doc.company))
return ret
def set_supplier_defaults(self):

View File

@ -132,7 +132,7 @@ erpnext.POS = Class.extend({
"options": "Item Group",
"label": "Item Group",
"fieldname": "pos_item_group",
"placeholder": "Filter by Item Group"
"placeholder": "Item Group"
},
parent: this.wrapper.find(".item-group-area")
});
@ -150,7 +150,7 @@ erpnext.POS = Class.extend({
"options": "Item",
"label": "Item",
"fieldname": "pos_item",
"placeholder": "Select Item"
"placeholder": "Item"
},
parent: this.wrapper.find(".search-area")
});
@ -167,7 +167,7 @@ erpnext.POS = Class.extend({
"fieldtype": "Data",
"label": "Barcode",
"fieldname": "pos_barcode",
"placeholder": "Select Barcode"
"placeholder": "Barcode"
},
parent: this.wrapper.find(".barcode-area")
});
@ -215,7 +215,9 @@ erpnext.POS = Class.extend({
// if form is local then allow this function
if (cur_frm.doc.docstatus===0) {
$("div.pos-item").on("click", function() {
if(!cur_frm.doc[me.party.toLowerCase()]) {
if(!cur_frm.doc[me.party.toLowerCase()] && ((me.frm.doctype == "Quotation" &&
cur_frm.doc.quotation_to == "Customer")
|| me.frm.doctype != "Quotation")) {
msgprint("Please select " + me.party + " first.");
return;
}
@ -282,6 +284,16 @@ erpnext.POS = Class.extend({
$.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name,
this.frm.cscript.fname, this.frm.doctype), function(i, d) {
if (me.sales_or_purchase == "Sales") {
item_amount = d.export_amount;
rate = d.export_rate;
}
else {
item_amount = d.import_amount;
rate = d.import_rate;
}
$(repl('<tr id="%(item_code)s" data-selected="false">\
<td>%(item_code)s%(item_name)s</td>\
<td><input type="text" value="%(qty)s" \
@ -292,8 +304,8 @@ erpnext.POS = Class.extend({
item_code: d.item_code,
item_name: d.item_name===d.item_code ? "" : ("<br>" + d.item_name),
qty: d.qty,
rate: format_currency(d.ref_rate, cur_frm.doc.currency),
amount: format_currency(d.export_amount, cur_frm.doc.currency)
rate: format_currency(rate, cur_frm.doc.currency),
amount: format_currency(item_amount, cur_frm.doc.currency)
}
)).appendTo($items);
});
@ -312,15 +324,24 @@ erpnext.POS = Class.extend({
<tr>', {
description: d.description,
rate: d.rate,
tax_amount: format_currency(d.tax_amount, me.frm.doc.currency)
tax_amount: format_currency(flt(d.tax_amount)/flt(me.frm.doc.conversion_rate),
me.frm.doc.currency)
})).appendTo(".tax-table tbody");
});
// set totals
this.wrapper.find(".net-total").text(format_currency(this.frm.doc.net_total_export,
cur_frm.doc.currency));
this.wrapper.find(".grand-total").text(format_currency(this.frm.doc.grand_total_export,
cur_frm.doc.currency));
if (this.sales_or_purchase == "Sales") {
this.wrapper.find(".net-total").text(format_currency(this.frm.doc.net_total_export,
cur_frm.doc.currency));
this.wrapper.find(".grand-total").text(format_currency(this.frm.doc.grand_total_export,
cur_frm.doc.currency));
}
else {
this.wrapper.find(".net-total").text(format_currency(this.frm.doc.net_total_import,
cur_frm.doc.currency));
this.wrapper.find(".grand-total").text(format_currency(this.frm.doc.grand_total_import,
cur_frm.doc.currency));
}
// if form is local then only run all these functions
if (cur_frm.doc.docstatus===0) {
@ -366,9 +387,12 @@ erpnext.POS = Class.extend({
if (this.frm.doctype != "Sales Invoice")
$(".make-payment").hide();
if (this.frm.doctype == "Quotation")
if (cur_frm.doc.quotation_to=="Customer")
this.party_field.remove();
// If quotation to is not Customer then remove party
if (this.frm.doctype == "Quotation") {
this.party_field.$wrapper.remove();
if (cur_frm.doc.quotation_to == "Customer")
this.make_party();
}
},
refresh_delete_btn: function() {
$(".delete-items").toggle($(".item-cart .warning").length ? true : false);

View File

@ -3,7 +3,6 @@
from __future__ import unicode_literals
import webnotes
from webnotes import msgprint, errprint
@webnotes.whitelist()
def get_items(price_list, sales_or_purchase, item=None, item_group=None):
@ -36,6 +35,11 @@ def get_item_from_barcode(barcode):
return webnotes.conn.sql("""select name from `tabItem` where barcode=%s""",
(barcode), as_dict=1)
@webnotes.whitelist()
def get_item_from_serial_no(serial_no):
return webnotes.conn.sql("""select name, item_code from `tabSerial No` where
name=%s""", (serial_no), as_dict=1)
@webnotes.whitelist()
def get_mode_of_payment():
return webnotes.conn.sql("""select name from `tabMode of Payment`""", as_dict=1)

View File

@ -108,8 +108,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
var item = wn.model.get_doc(cdt, cdn);
if(item.item_code) {
if(!this.validate_company_and_party("supplier")) {
item.item_code = null;
refresh_field("item_code", item.name, item.parentfield);
cur_frm.fields_dict[me.frm.cscript.fname].grid.grid_rows[item.idx - 1].remove();
} else {
return this.frm.call({
method: "buying.utils.get_item_details",

View File

@ -232,6 +232,29 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
tax_rate: function(doc, cdt, cdn) {
this.calculate_taxes_and_totals();
},
// serial_no: function(doc, cdt, cdn) {
// var me = this;
// var item = wn.model.get_doc(cdt, cdn);
// if (!item.item_code) {
// wn.call({
// method: 'accounts.doctype.sales_invoice.pos.get_item_from_serial_no',
// args: {serial_no: this.serial_no.$input.val()},
// callback: function(r) {
// if (r.message) {
// var item_code = r.message[0].item_code;
// var child = wn.model.add_child(me.frm.doc, this.frm.doctype + " Item",
// this.frm.cscript.fname);
// child.item_code = item_code;
// me.frm.cscript.item_code(me.frm.doc, child.doctype, child.name);
// }
// else
// msgprint(wn._("Invalid Serial No."));
// me.refresh();
// }
// });
// }
// },
row_id: function(doc, cdt, cdn) {
var tax = wn.model.get_doc(cdt, cdn);

View File

@ -162,8 +162,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
var item = wn.model.get_doc(cdt, cdn);
if(item.item_code || item.barcode) {
if(!this.validate_company_and_party("customer")) {
item.item_code = null;
refresh_field("item_code", item.name, item.parentfield);
cur_frm.fields_dict[me.frm.cscript.fname].grid.grid_rows[item.idx - 1].remove();
} else {
return this.frm.call({
method: "selling.utils.get_item_details",

View File

@ -34,6 +34,7 @@ def get_item_details(args):
"plc_conversion_rate": 1.0
}
"""
if isinstance(args, basestring):
args = json.loads(args)
args = webnotes._dict(args)

View File

@ -425,6 +425,7 @@ def get_address_territory(address_doc):
def validate_conversion_rate(currency, conversion_rate, conversion_rate_label, company):
"""common validation for currency and price list currency"""
if conversion_rate == 0:
msgprint(conversion_rate_label + _(' cannot be 0'), raise_exception=True)