[pos] pos view fixed for all purchase & sales cycle
diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py
index 0538323..ad7ebd9 100644
--- a/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -62,19 +62,20 @@
"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 4ef2397..ca5618b 100644
--- a/accounts/doctype/sales_invoice/pos.js
+++ b/accounts/doctype/sales_invoice/pos.js
@@ -132,7 +132,7 @@
"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 @@
"options": "Item",
"label": "Item",
"fieldname": "pos_item",
- "placeholder": "Select Item"
+ "placeholder": "Item"
},
parent: this.wrapper.find(".search-area")
});
@@ -167,7 +167,7 @@
"fieldtype": "Data",
"label": "Barcode",
"fieldname": "pos_barcode",
- "placeholder": "Select Barcode"
+ "placeholder": "Barcode"
},
parent: this.wrapper.find(".barcode-area")
});
@@ -215,7 +215,9 @@
// 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 @@
$.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 @@
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 @@
<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 @@
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 d919c1b..44fe40d 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):
@@ -37,5 +36,10 @@
(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 2dfe655..433a76f 100644
--- a/buying/doctype/purchase_common/purchase_common.js
+++ b/buying/doctype/purchase_common/purchase_common.js
@@ -108,8 +108,7 @@
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 1a1c98c..e12d108 100644
--- a/public/js/transaction.js
+++ b/public/js/transaction.js
@@ -232,6 +232,29 @@
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 dc58377..c87e823 100644
--- a/selling/doctype/sales_common/sales_common.js
+++ b/selling/doctype/sales_common/sales_common.js
@@ -162,8 +162,7 @@
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 224944d..801d82b 100644
--- a/selling/utils/__init__.py
+++ b/selling/utils/__init__.py
@@ -34,6 +34,7 @@
"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 2535db7..57591fd 100644
--- a/utilities/transaction_base.py
+++ b/utilities/transaction_base.py
@@ -425,6 +425,7 @@
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)