Deduct the quantity on Purchase order creation

Hi community,
I need to write a custom script to deduct the inventory on creation of a Purchase order.
Like i have a multi company setup.
Consider company A creating a Purchase order to company B,
So when we submit a purchase order ,the quantity of items in Company B’s warehouse should automatically get deducted.
Is there a way to achieve this??

write a server side script with the specific condition for material transfer from company b’s warehouse , save & submit , call this func from submission of purchase order submission.

Material transfer? or Material issue?. I just want to deduct from company b’s warehouse
Also are there any tutorials for server side scripting with such use case scenarios ? i am completely new to this framework.

if you just want to just deduct the stock, then material issue will suffice, i was thinking of some kind of reserve warehouse, thus the transfer.

this is a good place to start, and there are lots of posts in community for almost everything,
if you are stuck somewhere, feel free to pm, i’d gladly help with what i know

1 Like

Really appreciate this.
Will try the workaround u’ve suggested.

this code is for material issue, one i use,

	mr = frappe.new_doc("Stock Entry")
	mr.title = "Material Issue - " +
	mr.stock_entry_type = "Material Issue"
	mr.job_card_no = = company
	for item_entry in doc.get("items"):
			mr.append("items", {
				"item_code": item_entry.item_code,
				"uom": "Nos",
				"s_warehouse": item_entry.warehouse_del,
				"qty": float(item_entry.require_qty),
				"conversion_factor": float(1)

How do we select which warehouse should be used for deduction??

this line takes warehouse from item table in the current doc

Why don’t you build the code so that as part of the Submit process of the PO, A Sales Invoice with Update Stock Checked is submitted for the Source Company and a Purchase Invoice with Update Stock checked is submitted for the Target (or destination company). You could even add two payment entries for Internal Settlement/Transfer just so all loose ends are tied up nicely and standard reports on ERPNext (for example PO Items to be Dispatched, etc. etc.) all show data that is accurate.

Hope this helps.



Hey Thanks.
Yes i am currently working on creating a Stock Entry(Material Issue) on Submit process of a PO.As that would serve the purpose for now.