Skip to content

Commit

Permalink
feat: "Create Item" button
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Aug 26, 2024
1 parent 78fbe0c commit 841a635
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ frappe.ui.form.on("E Invoice Import", {
});
},
});

frappe.ui.form.on("E Invoice Item", {
create_item: function (frm, cdt, cdn) {
frappe.model.open_mapped_doc({
method: "eu_einvoice.european_e_invoice.doctype.e_invoice_import.e_invoice_import.create_item",
source_name: cdn,
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,35 @@ def post_process(source, target):
target_doc,
post_process,
)


@frappe.whitelist()
def create_item(source_doc, target_doc=None):
def post_process(source, target):
if frappe.db.get_single_value("Stock Settings", "item_naming_by") == "Item Code":
target.item_code = target.item_name
target.is_purchase_item = 1
target.append(
"supplier_items",
{
"supplier": frappe.db.get_value("E Invoice Import", source.parent, "supplier"),
"supplier_part_no": source.seller_product_id,
},
)

return get_mapped_doc(
"E Invoice Item",
source_doc,
{
"E Invoice Item": {
"doctype": "Item",
"field_map": {
"product_name": "item_name",
"product_description": "description",
"uom": "stock_uom",
},
}
},
target_doc,
post_process,
)
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,17 @@
},
{
"default": "0",
"depends_on": "eval: !doc.item",
"fieldname": "create_item",
"fieldtype": "Check",
"fieldtype": "Button",
"label": "Create Item",
"read_only_depends_on": "item"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-08-25 16:31:31.794308",
"modified": "2024-08-26 14:10:15.375742",
"modified_by": "Administrator",
"module": "European e-Invoice",
"name": "E Invoice Item",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class EInvoiceItem(Document):
from frappe.types import DF

billed_quantity: DF.Float
create_item: DF.Check
item: DF.Link | None
net_rate: DF.Float
parent: DF.Data
Expand Down

0 comments on commit 841a635

Please sign in to comment.