Hi @pstary,
As per your scenario, we configure and set the script. So please check it.
Item Buying Price (Standard Buying):
Here, I added a custom button in Item Doctype. When you click on the Show Item Price button then will show the dialog box which you want.
Output:
Please go to the Client script doctype and Select the Item Doctype.
Code:
frappe.ui.form.on('Item', {
refresh: function(frm) {
frm.add_custom_button(__('Show Item Buying Price'), function() {
get_buying_price(frm);
}, __("View"));
},
});
function get_buying_price(frm){
buying_price = frappe.db.get_list('Item Price', {
fields: ['item_code', 'price_list', 'price_list_rate', 'valid_from', 'valid_upto'],
filters: [
["Item Price", "buying", "=", 1],
["Item Price", 'item_code', "=", frm.doc.item_code],
["Item Price", 'price_list', "=", "Standard Buying"]
],
as_list: 1
}).then(function(val) {
let data = frappe.utils.dict(["item_code", "price_list", "price_list_rate", "valid_from", "valid_upto"], val);
const table_fields = [
{
label: 'Item Code',
fieldname: 'item_code',
fieldtype: 'Link',
options: 'Item',
in_list_view: 1,
read_only: 1
},
{
label: 'Price List',
fieldname: 'price_list',
fieldtype: 'Link',
options: 'Price List',
in_list_view: 1,
read_only: 1
},
{
label: 'Price List Rate',
fieldname: 'price_list_rate',
fieldtype: 'Currency',
in_list_view: 1,
read_only: 1
},
{
label: 'Valid From',
fieldname: 'valid_from',
fieldtype: 'Date',
in_list_view: 1,
read_only: 1
},
{
label: 'Valid Upto',
fieldname: 'valid_upto',
fieldtype: 'Date',
in_list_view: 1,
read_only: 1
}
];
let d = new frappe.ui.Dialog({
title: 'Item Buying Price: ' + frm.doc.item_code,
size: "large",
fields: [
{
label: 'Items',
fieldname: 'items_buying_price',
fieldtype: 'Table',
fields: table_fields,
options: 'Item',
cannot_add_rows: 1,
cannot_delete_rows : 1,
data: data
},
],
primary_action_label: 'Close',
primary_action(values) {
d.hide();
}
});
d.show();
}
)}
I hope this helps.
Thank You!