Code cleanup online POS (#12985)
This commit is contained in:
parent
a5003f8f5b
commit
554f2de23d
@ -32,7 +32,7 @@ class POSProfile(Document):
|
|||||||
.format(res[0][0], row.user), raise_exception=1)
|
.format(res[0][0], row.user), raise_exception=1)
|
||||||
elif not row.default and not res:
|
elif not row.default and not res:
|
||||||
msgprint(_("User {0} doesn't have any default POS Profile. Check Default at Row {1} for this User.")
|
msgprint(_("User {0} doesn't have any default POS Profile. Check Default at Row {1} for this User.")
|
||||||
.format(row.user, row.idx), raise_exception=1)
|
.format(row.user, row.idx))
|
||||||
|
|
||||||
def validate_all_link_fields(self):
|
def validate_all_link_fields(self):
|
||||||
accounts = {"Account": [self.income_account,
|
accounts = {"Account": [self.income_account,
|
||||||
|
|||||||
@ -106,6 +106,10 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
|
|||||||
on_submit: function(doc, dt, dn) {
|
on_submit: function(doc, dt, dn) {
|
||||||
var me = this;
|
var me = this;
|
||||||
|
|
||||||
|
if (frappe.get_route()[0] != 'Sales Invoice') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
$.each(doc["items"], function(i, row) {
|
$.each(doc["items"], function(i, row) {
|
||||||
if(row.delivery_note) frappe.model.clear_doc("Delivery Note", row.delivery_note)
|
if(row.delivery_note) frappe.model.clear_doc("Delivery Note", row.delivery_note)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -256,17 +256,22 @@ erpnext.pos.PointOfSale = class PointOfSale {
|
|||||||
if (field == 'qty' && value < 0) {
|
if (field == 'qty' && value < 0) {
|
||||||
frappe.msgprint(__("Quantity must be positive"));
|
frappe.msgprint(__("Quantity must be positive"));
|
||||||
value = item.qty;
|
value = item.qty;
|
||||||
|
} else {
|
||||||
|
item[field] = value;
|
||||||
|
if (field == "serial_no" && value) {
|
||||||
|
let serial_nos = value.split("\n");
|
||||||
|
item["qty"] = serial_nos.filter(d => {
|
||||||
|
return d!=="";
|
||||||
|
}).length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field) {
|
return this.frm.script_manager.trigger('qty', item.doctype, item.name)
|
||||||
return frappe.model.set_value(item.doctype, item.name, field, value)
|
.then(() => {
|
||||||
.then(() => this.frm.script_manager.trigger('qty', item.doctype, item.name))
|
if (field === 'qty' && item.qty === 0) {
|
||||||
.then(() => {
|
frappe.model.clear_doc(item.doctype, item.name);
|
||||||
if (field === 'qty' && item.qty === 0) {
|
}
|
||||||
frappe.model.clear_doc(item.doctype, item.name);
|
})
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
@ -283,20 +288,13 @@ erpnext.pos.PointOfSale = class PointOfSale {
|
|||||||
}
|
}
|
||||||
|
|
||||||
submit_sales_invoice() {
|
submit_sales_invoice() {
|
||||||
|
this.frm.savesubmit()
|
||||||
frappe.confirm(__("Permanently Submit {0}?", [this.frm.doc.name]), () => {
|
.then((r) => {
|
||||||
frappe.call({
|
if (r && r.doc) {
|
||||||
method: 'erpnext.selling.page.point_of_sale.point_of_sale.submit_invoice',
|
this.frm.doc.docstatus = r.doc.docstatus;
|
||||||
freeze: true,
|
|
||||||
args: {
|
|
||||||
doc: this.frm.doc
|
|
||||||
}
|
|
||||||
}).then(r => {
|
|
||||||
if(r.message) {
|
|
||||||
this.frm.doc = r.message;
|
|
||||||
frappe.show_alert({
|
frappe.show_alert({
|
||||||
indicator: 'green',
|
indicator: 'green',
|
||||||
message: __(`Sales invoice ${r.message.name} created succesfully`)
|
message: __(`Sales invoice ${r.doc.name} created succesfully`)
|
||||||
});
|
});
|
||||||
|
|
||||||
this.toggle_editing();
|
this.toggle_editing();
|
||||||
@ -304,21 +302,22 @@ erpnext.pos.PointOfSale = class PointOfSale {
|
|||||||
this.set_primary_action_in_modal();
|
this.set_primary_action_in_modal();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set_primary_action_in_modal() {
|
set_primary_action_in_modal() {
|
||||||
this.frm.msgbox = frappe.msgprint(
|
if (!this.frm.msgbox) {
|
||||||
`<a class="btn btn-primary" onclick="cur_frm.print_preview.printit(true)" style="margin-right: 5px;">
|
this.frm.msgbox = frappe.msgprint(
|
||||||
${__('Print')}</a>
|
`<a class="btn btn-primary" onclick="cur_frm.print_preview.printit(true)" style="margin-right: 5px;">
|
||||||
<a class="btn btn-default">
|
${__('Print')}</a>
|
||||||
${__('New')}</a>`
|
<a class="btn btn-default">
|
||||||
);
|
${__('New')}</a>`
|
||||||
|
);
|
||||||
|
|
||||||
$(this.frm.msgbox.body).find('.btn-default').on('click', () => {
|
$(this.frm.msgbox.body).find('.btn-default').on('click', () => {
|
||||||
this.frm.msgbox.hide();
|
this.frm.msgbox.hide();
|
||||||
this.make_new_invoice();
|
this.make_new_invoice();
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
change_pos_profile() {
|
change_pos_profile() {
|
||||||
@ -487,11 +486,6 @@ erpnext.pos.PointOfSale = class PointOfSale {
|
|||||||
//
|
//
|
||||||
// }).addClass('visible-xs');
|
// }).addClass('visible-xs');
|
||||||
|
|
||||||
this.page.add_menu_item(__("Form View"), function () {
|
|
||||||
frappe.model.sync(me.frm.doc);
|
|
||||||
frappe.set_route("Form", me.frm.doc.doctype, me.frm.doc.name);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.page.add_menu_item(__("POS Profile"), function () {
|
this.page.add_menu_item(__("POS Profile"), function () {
|
||||||
frappe.set_route('List', 'POS Profile');
|
frappe.set_route('List', 'POS Profile');
|
||||||
});
|
});
|
||||||
@ -589,6 +583,7 @@ class POSCart {
|
|||||||
this.$taxes_and_totals.html(this.get_taxes_and_totals());
|
this.$taxes_and_totals.html(this.get_taxes_and_totals());
|
||||||
this.numpad && this.numpad.reset_value();
|
this.numpad && this.numpad.reset_value();
|
||||||
this.customer_field.set_value("");
|
this.customer_field.set_value("");
|
||||||
|
this.frm.msgbox = "";
|
||||||
|
|
||||||
this.$discount_amount.find('input:text').val('');
|
this.$discount_amount.find('input:text').val('');
|
||||||
this.wrapper.find('.grand-total-value').text(
|
this.wrapper.find('.grand-total-value').text(
|
||||||
|
|||||||
@ -87,19 +87,6 @@ def get_conditions(item_code, serial_no, batch_no, barcode):
|
|||||||
|
|
||||||
return '%%%s%%'%(frappe.db.escape(item_code)), condition
|
return '%%%s%%'%(frappe.db.escape(item_code)), condition
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def submit_invoice(doc):
|
|
||||||
if isinstance(doc, basestring):
|
|
||||||
args = json.loads(doc)
|
|
||||||
|
|
||||||
doc = frappe.new_doc('Sales Invoice')
|
|
||||||
doc.update(args)
|
|
||||||
doc.run_method("set_missing_values")
|
|
||||||
doc.run_method("calculate_taxes_and_totals")
|
|
||||||
doc.submit()
|
|
||||||
|
|
||||||
return doc
|
|
||||||
|
|
||||||
def get_item_group_condition(pos_profile):
|
def get_item_group_condition(pos_profile):
|
||||||
cond = "and 1=1"
|
cond = "and 1=1"
|
||||||
item_groups = get_item_groups(pos_profile)
|
item_groups = get_item_groups(pos_profile)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user