Skip to content

Commit

Permalink
feat: facilitate manual selection of PO row
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Dec 31, 2024
1 parent 263a0cf commit 0ad6c78
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ frappe.ui.form.on("E Invoice Import", {
};
});

frm.set_query("po_detail", "items", function (doc, cdt, cdn) {
const row = locals[cdt][cdn];
return {
query: "eu_einvoice.european_e_invoice.doctype.e_invoice_import.e_invoice_import.po_item_query",
filters: {
parent: doc.purchase_order,
item_code: row.item,
},
};
});

frm.set_query("tax_account", "taxes", function (doc, cdt, cdn) {
return {
filters: {
Expand Down Expand Up @@ -109,4 +120,25 @@ frappe.ui.form.on("E Invoice Item", {
source_name: cdn,
});
},

po_detail: function (frm, cdt, cdn) {
const row = locals[cdt][cdn];
if (!row.po_detail || (row.item && row.uom) || !frappe.model.can_read("Purchase Order")) {
return;
}

frappe
.xcall(
"eu_einvoice.european_e_invoice.doctype.e_invoice_import.e_invoice_import.get_po_item_details",
{ po_detail: row.po_detail }
)
.then((r) => {
if (r.item_code && !row.item) {
frappe.model.set_value(cdt, cdn, "item", r.item_code);
}
if (r.uom && !row.uom) {
frappe.model.set_value(cdt, cdn, "uom", r.uom);
}
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,43 @@ def link_to_purchase_invoice(einvoice: str, purchase_invoice: str):
frappe.throw(_("E Invoice Import {0} does not exist").format(einvoice))

pi.db_set("e_invoice_import", einvoice)


@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def po_item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
item_code = filters.pop("item_code")
purchase_order = filters.pop("parent")

if not purchase_order:
return []

purchase_order = frappe.get_doc("Purchase Order", purchase_order)
purchase_order.check_permission("read")

return [
[
row.name,
_("Row {0}").format(row.idx),
row.item_code,
row.description[:100] + "..." if len(row.description) > 40 else row.description,
row.get_formatted("qty") + " " + row.uom,
row.get_formatted("net_rate") + " / " + row.uom,
]
for row in purchase_order.items
if not item_code or row.item_code == item_code
]


@frappe.whitelist()
def get_po_item_details(po_detail: str):
purchase_order_name = frappe.db.get_value("Purchase Order Item", po_detail, "parent")
purchase_order = frappe.get_doc("Purchase Order", purchase_order_name)
if not purchase_order.has_permission("read"):
return {}

row = purchase_order.getone("items", {"name": po_detail})
return {
"item_code": row.item_code,
"uom": row.uom,
}

0 comments on commit 0ad6c78

Please sign in to comment.