function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
force shahidforce shahid 

how to deduct raw material quantity after billing the order ?

Hi Friends,

I created app for restaurent . I created custom objects name as Bill , Order , Raw material . Now i want to write a trigger /something for deduct the rawmaterial after order is billing. howit is possible ?

Thanks in advance
 
Deepankar ChandaDeepankar Chanda
Information about the problem is very less like relationship between the objects, you have to add more information & what do you mean by deduct is it you want to deduct only the price/value of the raw material or want to remove the raw material records which is associated with the bill?

If I go with the exact word meaning of deducting & N:N relationship between the two objects then yes you can use trigger but to write a trigger you need to fix a trigger point, when your trigger will deduct the price of the raw material. 

say you are storing the total value of bill in bill object & then a simple trigger can help you to deduct it from child records. Adding more info will help to give more accurate answere. 

 
force shahidforce shahid
Hi Deepankar ,

Thanks for your reply.  I created relationship between menu Object and Raw material object. 
Parent is Rwa material, Child is Menu
Order is parent , child is billing .
When order is billing i need to deduct the raw materialof item .
Example :
One customer orderd  coffee ., Milk shake means 2 items. 
In menu Object i create Coffee is menu name and i took 10 ingrediant items & their quantity .
For coffee i took 3 ingrediants  with their respective quantity .
For milk Shake 4 ingrediants.

In raw material I took coffebeans is one record, sugar is one record , milk is one record.

If this order is billing  , i need to deduct the raw material quantity. How to write the trigger ? If it possible , can u provide the code .

Thanks in Advance. 
Deepankar ChandaDeepankar Chanda
Hello Shahid,

I think relationships what you have mentioned should be other way I am coming from your example only:

Menu & raw materials should be many to many relationship not parent child relationship, reason else everytime you have to create a new record for same raw materials. 
"In menu Object i create Coffee is menu name and i took 10 ingrediant items & their quantity ."

For this scenario I would have done this:

1. Created a Total Price field on Menu object which user will key in after every record creation
2. Created a Lookup relationship of Menu on Billing object which is a child to Order object
3. Created two fields one Line Price (Number) & another Price (formula field) which will add up to the Billing object
4. And last field Total Price on Menu object which will sum up the Line Prices from billing object record to Menu, this field will be a roll up summary field on Line Price of Billing object.

5. You have to create a workflow which will copy the Price value to Line Price
Formula Field

I hope with no code you can achieve it. 
 
force shahidforce shahid
Hi Deepankar ,
Thanks for your reply . But i want to deduct the raw material quantity . Not a price.
Deepankar ChandaDeepankar Chanda
Hello Shahid,

Then if you follow my suggested way of object creation & relationships then you don't have to care about getting rid of raw materials.

To make it more easy:

How the Order will be get created

Billing will have a lookup to Menu & the above attached screenshot only showinf Menu items along with Billing line item in Order.

Let me know if my explanation help you.
Deepankar ChandaDeepankar Chanda
Hello Shahid, Let me know if my explanation helped you to solve your problem.