Dears,
I need to fetch data from the database using the POS screen, other meaning i need to get the value to custom field in POS
Currently this is not out of the box…you need to customize POS page
I need example code to fetch data from another doctype to pos custom field
waiting for example also…
@Tarek_Esmail do you want add your custom field in pos?? if yes here i have added batch field in pos by customizing html and finding events in js see below i have taken pos_item.js where i am rendering batch no on pos
Here s html for pos_item
<div class="row pos-bill-row pos-bill-item" data-item-code="{%= item_code %}" item-idx="{%= idx %}">
<div class="col-xs-3"><h6>{%= item_code || "" %}{%= item_name || "" %}</h6></div>
<div class="col-xs-3">
<div class="row pos-batch-row">
<div class="batch-no"></div>
<input type="text" name="Production date" value="{%= production_date%}" style="margin-bottom: 1%;" class="form-control input-sm pos-item-batch-pro text-right" id="prod_date" placeholder="Production Date" readonly>
<input type="text" value="{%= expiry_date %}" style="margin-bottom: 1%;" class="form-control input-sm pos-item-batch-exp text-right" id="Expi_date" placeholder="Expiration Date" readonly>
</div>
</div>
<div class="col-xs-3">
<div class="row pos-qty-row">
<div class="col-xs-2 text-center pos-qty-btn" data-action="decrease-qty"><i class="fa fa-minus text-muted" style="font-size:12px"></i></div>
<div class="col-xs-8">
<div>
<input type="text" value="{%= qty %}" class="form-control input-sm pos-item-qty text-right">
</div>
{% if(actual_qty != null) { %}
<div style="margin-top: 5px;" class="text-muted small text-right">
<span title="{%= __("In Stock") %}">{%= actual_qty || 0 %}<span>
</div>
{% } %}
</div>
<div class="col-xs-2 text-center pos-qty-btn" data-action="increase-qty"><i class="fa fa-plus text-muted" style="font-size:12px"></i></div>
</div>
</div>
<div class="col-xs-3 text-right">
<div class="text-muted" style="margin-top: 5px;">
{% if(enabled) { %}
<input type="text" value="{%= rate %}" class="form-control input-sm pos-item-rate text-right">
{% } else { %}
<h6>{%= format_currency(rate) %}</h6>
{% } %}
</div>
<p><h6>{%= amount %}</h6></p>
</div>
</div>
below i am manipulating link field
render_batch_no:function(idx,expiry_date,batch_no,item_code){
var demo=$('div[item-idx='+idx+']')
var me=this;
var item_obj = $(this).parents(".pos-bill-item")
this.batch_no= frappe.ui.form.make_control({
df: {
"fieldtype": "Link",
"options": "Batch",
"label": "Batch-no",
"fieldname": "Batch",
"placeholder": __("Batch"),
"input_class":"batch-item-no",
"get_query":function(){
return {
"query":"goodfood_trading.customization.poss.return_query",
filters:{
"item_code":item_code
}
}
}
},
parent: $('div[item-idx='+idx+']').find(".batch-no"),
only_input: true,
});
this.batch_no.make_input();
$(this).find(".batch-no").val("hbh")
},
//Added By Khushal
get_batch_dates:function(){
var me=this
$(this.wrapper).find(".batch-item-no").on("change",function(){
var batch_no = $(this).val()
var item_idx = $(this).parents(".pos-bill-item").attr("item-idx");
var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
var item_obj = $(this).parents(".pos-bill-item")
console.log("QQQQQQQQQ",item_obj.attr("item-idx"),item_code,batch_no)
// console.log("TT",item_idx)
frappe.call({
method: "goodfood_trading.customization.poss.get_data",
args: {
"batch_item": batch_no
},
async:false,
callback: function(r) {
console.log("{}{}}{}{}}}{}{}{}{}")
me.batch_according_to_batch_no(item_code, batch_no, item_obj) // console.log("RRRRRRRRRRRRR",d.item_counter,d.item_code)
$('div[item-idx='+item_idx+']').find("#prod_date").val(r.message[0])
$('div[item-idx='+item_idx+']').find("#Expi_date").val(r.message[1])
}
})
})
},
here i am finding item add to cart event and attaching link field
render_batch_no
3 Likes
gave you reference code i hope will be helpful
Thank you @khushal_t for the reference code. Can you insert a screenshot of your customized POS? Thanks a lot.