Fixed serial no trigger not working from dialog box

This commit is contained in:
Rohit Waghchaure 2017-09-01 15:28:44 +05:30
parent 3e43927767
commit 6ab630371d
5 changed files with 87 additions and 32 deletions

View File

@ -8,10 +8,6 @@ frappe.ui.form.on("POS Profile", "onload", function(frm) {
return { filters: { selling: 1 } };
});
frm.set_query("print_format", function() {
return { filters: { doc_type: "Sales Invoice", print_format_type: "Js"} };
});
erpnext.queries.setup_queries(frm, "Warehouse", function() {
return erpnext.queries.warehouse(frm.doc);
});
@ -27,6 +23,27 @@ frappe.ui.form.on("POS Profile", "onload", function(frm) {
});
frappe.ui.form.on('POS Profile', {
setup: function(frm) {
frm.set_query("online_print_format", function() {
return {
filters: [
['Print Format', 'doc_type', '=', 'Sales Invoice'],
['Print Format', 'print_format_type', '!=', 'Js'],
]
};
});
frm.set_query("print_format", function() {
return { filters: { doc_type: "Sales Invoice", print_format_type: "Js"} };
});
frappe.db.get_value('POS Settings', {name: 'POS Settings'}, 'is_online', (r) => {
is_online = r && cint(r.is_online)
frm.toggle_display('offline_pos_section', !is_online);
frm.toggle_display('print_format_for_online', is_online);
});
},
refresh: function(frm) {
if(frm.doc.company) {
frm.trigger("toggle_display_account_head");

View File

@ -631,8 +631,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "Point of Sale",
"fieldname": "print_format",
"fieldname": "print_format_for_online",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
@ -641,7 +640,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Print Format",
"label": "Print Format for Online",
"length": 0,
"no_copy": 0,
"options": "Print Format",
@ -883,7 +882,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "customer_details",
"fieldname": "offline_pos_section",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
@ -892,7 +891,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "New Customer Details",
"label": "Offline POS Section",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@ -969,6 +968,38 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "Point of Sale",
"fieldname": "print_format",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Print Format",
"length": 0,
"no_copy": 0,
"options": "Print Format",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -1291,7 +1322,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-08-27 16:39:00.713225",
"modified": "2017-09-01 15:55:14.890452",
"modified_by": "Administrator",
"module": "Accounts",
"name": "POS Profile",

View File

@ -10,7 +10,7 @@
"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{{ __(\"POS No : \") }} {{ offline_pos_name }}<br>\n</p>\n<p>\n\t<b>{{ __(\"Customer\") }}:</b> {{ customer }}<br>\n</p>\n\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\">{{ format_number(item.qty, null,precision(\"difference\")) }}<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\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t<b>{{ __(\"Paid Amount\") }}</b>\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(paid_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n\n\n<hr>\n<p>{{ terms }}</p>\n<p class=\"text-center\">{{ __(\"Thank you, please visit again.\") }}</p>",
"idx": 0,
"line_breaks": 0,
"modified": "2017-05-19 14:36:04.740728",
"modified": "2017-09-01 14:27:04.871233",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Point of Sale",

View File

@ -4,6 +4,7 @@
erpnext.TransactionController = erpnext.taxes_and_totals.extend({
setup: function() {
this._super();
frappe.flags.hide_serial_batch_dialog = false;
frappe.ui.form.on(this.frm.doctype + " Item", "rate", function(frm, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
var has_margin_field = frappe.meta.has_field(cdt, 'margin_type');
@ -314,12 +315,15 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
if(!r.exc) {
me.frm.script_manager.trigger("price_list_rate", cdt, cdn);
me.toggle_conversion_factor(item);
if(show_batch_dialog) {
if(show_batch_dialog && !frappe.flags.hide_serial_batch_dialog) {
var d = locals[cdt][cdn];
$.each(r.message, function(k, v) {
if(!d[k]) d[k] = v;
});
erpnext.show_serial_batch_selector(me.frm, d);
erpnext.show_serial_batch_selector(me.frm, d, (item) => {
me.frm.script_manager.trigger('qty', item.doctype, item.name);
});
}
}
}
@ -1102,7 +1106,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
},
});
erpnext.show_serial_batch_selector = function(frm, d) {
erpnext.show_serial_batch_selector = function(frm, d, callback, show_dialog) {
frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() {
new erpnext.SerialNoBatchSelector({
frm: frm,
@ -1111,6 +1115,7 @@ erpnext.show_serial_batch_selector = function(frm, d) {
type: "Warehouse",
name: d.warehouse
},
});
callback: callback
}, show_dialog);
});
}

View File

@ -139,6 +139,7 @@ class PointOfSale {
update_item_in_cart(item_code, field='qty', value=1) {
if(this.cart.exists(item_code)) {
const item = this.frm.doc.items.find(i => i.item_code === item_code);
frappe.flags.hide_serial_batch_dialog = false;
if (typeof value === 'string' && !in_list(['serial_no', 'batch_no'], field)) {
// value can be of type '+1' or '-1'
@ -168,29 +169,28 @@ class PointOfSale {
// add to cur_frm
const item = this.frm.add_child('items', args);
frappe.flags.hide_serial_batch_dialog = true;
this.frm.script_manager
.trigger('item_code', item.doctype, item.name)
.then(() => {
// update cart
this.update_cart_data(item);
const show_dialog = item.has_serial_no || item.has_batch_no;
if (show_dialog && field == 'qty') {
// check has serial no/batch no and update cart
this.select_batch_and_serial_no(item);
} else {
// update cart
this.update_cart_data(item);
}
});
}
select_batch_and_serial_no(item) {
new erpnext.SerialNoBatchSelector({
frm: this.frm,
item: item,
warehouse_details: {
type: "Warehouse",
name: item.warehouse
},
callback: (item) => {
this.update_item_in_frm(item)
.then(() => {
// update cart
this.update_cart_data(item);
});
}
erpnext.show_serial_batch_selector(this.frm, item, () => {
this.update_item_in_frm(item)
.then(() => {
// update cart
this.update_cart_data(item);
});
}, true);
}
@ -308,7 +308,6 @@ class PointOfSale {
frm.doc.items = [];
frm.set_value('is_pos', 1);
frm.meta.default_print_format = 'POS Invoice';
return frm;
}
}
@ -340,6 +339,9 @@ class PointOfSale {
if(this.frm.doc.docstatus !== 1) return;
this.page.set_secondary_action(__("Print"), () => {
if (this.pos_profile && this.pos_profile.print_format_for_online) {
this.frm.meta.default_print_format = this.pos_profile.print_format_for_online;
}
this.frm.print_preview.printit(true);
});