Skip to content

Commit

Permalink
fix: item_query in pos_invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
ljain112 committed Sep 17, 2024
1 parent ce34bb9 commit 7f82a06
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
13 changes: 13 additions & 0 deletions erpnext/accounts/doctype/pos_invoice/pos_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex
};
});

this.frm.set_query("item_code", "items", function (doc) {
return {
query: "erpnext.accounts.doctype.pos_invoice.pos_invoice.item_query",
filters: {
has_variants: ["=", 0],
is_sales_item: ["=", 1],
disabled: ["=", 0],
is_fixed_asset: ["=", 0],
pos_profile: ["=", doc.pos_profile],
},
};
});

erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
}

Expand Down
28 changes: 28 additions & 0 deletions erpnext/accounts/doctype/pos_invoice/pos_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from frappe import _, bold
from frappe.query_builder.functions import IfNull, Sum
from frappe.utils import cint, flt, get_link_to_form, getdate, nowdate
from frappe.utils.nestedset import get_descendants_of

from erpnext.accounts.doctype.loyalty_program.loyalty_program import validate_loyalty_points
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request
Expand All @@ -15,6 +16,7 @@
update_multi_mode_option,
)
from erpnext.accounts.party import get_due_date, get_party_account
from erpnext.controllers.queries import item_query as _item_query
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos


Expand Down Expand Up @@ -840,3 +842,29 @@ def append_payment(payment_mode):
]:
payment_mode = get_mode_of_payment_info(mode_of_payment, doc.company)
append_payment(payment_mode[0])


@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
if pos_profile := filters.get("pos_profile")[1]:
pos_profile = frappe.get_cached_doc("POS Profile", pos_profile)
if item_groups := get_item_group(pos_profile):
filters["item_group"] = ["in", tuple(item_groups)]

del filters["pos_profile"]

else:
filters.pop("pos_profile", None)

return _item_query(doctype, txt, searchfield, start, page_len, filters, as_dict)


def get_item_group(pos_profile):
item_groups = []
if pos_profile.get("item_groups"):
# Get items based on the item groups defined in the POS profile
for row in pos_profile.get("item_groups"):
item_groups.extend(get_descendants_of("Item Group", row.item_group))

return list(set(item_groups))

0 comments on commit 7f82a06

Please sign in to comment.