Skip to content

Commit

Permalink
fix(pos): filter on customer groups
Browse files Browse the repository at this point in the history
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
(cherry picked from commit cc63415)
  • Loading branch information
ssiyad authored and mergify[bot] committed Nov 29, 2022
1 parent e093c32 commit c1ae5b0
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions erpnext/accounts/doctype/pos_invoice/pos_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
frappe.provide("erpnext.accounts");

erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnext.selling.SellingController {
settings = {};

setup(doc) {
this.setup_posting_date_time_check();
super.setup(doc);
Expand All @@ -25,8 +27,13 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
}

onload_post_render(frm) {
this.pos_profile(frm);
}

refresh(doc) {
super.refresh();

if (doc.docstatus == 1 && !doc.is_return) {
this.frm.add_custom_button(__('Return'), this.make_sales_return, __('Create'));
this.frm.page.set_inner_btn_group_as_primary(__('Create'));
Expand All @@ -36,6 +43,18 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex
this.frm.return_print_format = "Sales Invoice Return";
this.frm.set_value('consolidated_invoice', '');
}

this.frm.set_query("customer", (function () {
const customer_groups = this.settings?.customer_groups;

if (!customer_groups?.length) return {};

return {
filters: {
customer_group: ["in", customer_groups],
}
}
}).bind(this));
}

is_pos() {
Expand Down Expand Up @@ -88,6 +107,25 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex
});
}

pos_profile(frm) {
if (!frm.pos_profile || frm.pos_profile == '') {
this.update_customer_groups_settings([]);
return;
}

frappe.call({
method: "erpnext.selling.page.point_of_sale.point_of_sale.get_pos_profile_data",
args: { "pos_profile": frm.pos_profile },
callback: ({ message: profile }) => {
this.update_customer_groups_settings(profile?.customer_groups);
},
});
}

update_customer_groups_settings(customer_groups) {
this.settings.customer_groups = customer_groups?.map((group) => group.name)
}

amount(){
this.write_off_outstanding_amount_automatically()
}
Expand Down

0 comments on commit c1ae5b0

Please sign in to comment.