import{api as y}from"./common-DEIQtiPI.js";import"./index-DOFLUERq.js";function v(o){async function m(n){const{value:i,record:t,parentDoc:s,pagetype:l}=n;if(i)try{const a=s||{},r=t,c={...a,pagetype:a.pagetype||l,__islocal:a.name?0:1},p=await y.call("jerp.stock.get_item_details.get_item_details",{pg:c,args:{item_code:i,warehouse:r.warehouse||a.set_warehouse,customer:o.partyField==="customer"?a.customer||a.party_name:void 0,supplier:o.partyField==="supplier"?a.supplier:void 0,currency:a.currency,company:a.company,price_list:a[o.priceListField],qty:r.qty||1,uom:r.uom,conversion_factor:r.conversion_factor||1,pagetype:c.pagetype,name:a.name,child_pagetype:r.pagetype||o.childPagetype,child_pagename:r.name}});if(p?.message){const e=p.message;e.item_name&&(t.item_name=e.item_name),e.description&&(t.description=e.description),e.stock_uom&&(t.stock_uom=e.stock_uom),e.uom&&(t.uom=e.uom),e.conversion_factor&&(t.conversion_factor=e.conversion_factor),e.warehouse&&(t.warehouse=e.warehouse),e.qty!==void 0&&(t.qty=e.qty),e.rate!==void 0&&e.rate>0?t.rate=e.rate:e.price_list_rate!==void 0&&e.price_list_rate>0&&(t.rate=e.price_list_rate),e.price_list_rate!==void 0&&(t.price_list_rate=e.price_list_rate),e.discount_percentage!==void 0&&(t.discount_percentage=e.discount_percentage);const u=t.qty||1,d=t.rate||0;t.amount=u*d,e.base_rate!==void 0&&(t.base_rate=e.base_rate),e.base_amount!==void 0&&(t.base_amount=e.base_amount),e.item_tax_template&&(t.item_tax_template=e.item_tax_template)}}catch(a){console.error("[itemDetails plugin] Failed:",a)}}function _(n){const{record:i}=n;if(i.qty===void 0&&i.rate===void 0)return;const t=Number(i.qty)||0,s=Number(i.rate)||0;i.amount=t*s}return[{fieldname:"item_code",handler:m},{fieldname:["qty","rate"],handler:_}]}export{v as createItemDetailsPlugin};
