From 10dce341c823d107d81246a87c07a82bcf1ca90b Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Wed, 25 Sep 2013 11:09:33 +0530 Subject: [PATCH] [pos] pos view fixed for all purchase & sales cycle --- .../purchase_invoice/purchase_invoice.py | 25 ++++----- accounts/doctype/sales_invoice/pos.js | 52 ++++++++++++++----- accounts/doctype/sales_invoice/pos.py | 6 ++- .../purchase_common/purchase_common.js | 3 +- public/js/transaction.js | 23 ++++++++ selling/doctype/sales_common/sales_common.js | 3 +- selling/utils/__init__.py | 1 + utilities/transaction_base.py | 1 + 8 files changed, 83 insertions(+), 31 deletions(-) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index 0538323561..ad7ebd90de 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -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): diff --git a/accounts/doctype/sales_invoice/pos.js b/accounts/doctype/sales_invoice/pos.js index 4ef239744b..ca5618b345 100644 --- a/accounts/doctype/sales_invoice/pos.js +++ b/accounts/doctype/sales_invoice/pos.js @@ -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('\ %(item_code)s%(item_name)s\ " + 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({ ', { 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); diff --git a/accounts/doctype/sales_invoice/pos.py b/accounts/doctype/sales_invoice/pos.py index d919c1b548..44fe40d8de 100644 --- a/accounts/doctype/sales_invoice/pos.py +++ b/accounts/doctype/sales_invoice/pos.py @@ -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) \ No newline at end of file diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index 2dfe65515a..433a76fba7 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -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", diff --git a/public/js/transaction.js b/public/js/transaction.js index 1a1c98ca6b..e12d1084e9 100644 --- a/public/js/transaction.js +++ b/public/js/transaction.js @@ -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); diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js index dc58377e4b..c87e823dba 100644 --- a/selling/doctype/sales_common/sales_common.js +++ b/selling/doctype/sales_common/sales_common.js @@ -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", diff --git a/selling/utils/__init__.py b/selling/utils/__init__.py index 224944dd88..801d82bf40 100644 --- a/selling/utils/__init__.py +++ b/selling/utils/__init__.py @@ -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) diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py index 2535db7ab5..57591fd321 100644 --- a/utilities/transaction_base.py +++ b/utilities/transaction_base.py @@ -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)