Skip to content

[Enhancement] Work Order Material Consumption#13384

Merged
nabinhait merged 6 commits intofrappe:developfrom
newmatik:material_consumption
Apr 9, 2018
Merged

[Enhancement] Work Order Material Consumption#13384
nabinhait merged 6 commits intofrappe:developfrom
newmatik:material_consumption

Conversation

@creamdory
Copy link
Copy Markdown
Contributor

Made the enhancements from these issues:

#13368
#13369
#13368

BOM:

bom

Usecases:

Usecase:

1 transfer, 1 consumption and 1 Finish from a Work Order

  • Work Order

work order 1

  • Material Transfer

full material transfer

  • Material Consumption

full consumption

  • Work Order Completion

fulll finish

Usecase:

Multiple Transfer, Consumption and Finish from a Work Order.

  • Work Order
    work order 2

  • Partial Stock Transfer suggest only "Required Qty" * "Qty for Material Transfer for Manufacture". If we click "Finish" before any "Material Consumption", must suggest Qty to consumed in the Manufacture Stock Entry. If we create "Material Consumption for Manufacture" before "Finish", must take into account the "Consumed Qty" during Finish.

1 transfer 1 consumption 2 finish

Usecase:

Work Order with Partial transfer, consumption and completion.

work order

  • Material Transfer : Suggest the total Stock to be transferred from the "Required Qty" column and the "Qty for Material Transfer for Manufacture".

stock transfer

  • Material Consumption : Suggest and allow only consumption less than or equal to the "Transferred Qty".

material consumption

  • Finish Production : Suggest consumption of materials less than the "Consumed Qty" and base total consumption qty from the "Qty for Manufacture".

finish

Validations

  1. Doesn't allow consumption more than Transferred Qty.

dont allow consumption more than transfer

  1. Allow Transfer more than the Required Qty. Allow Consumption more than required Qty.
  2. Doesn't allow cancellation of "Material Consumption for Manufacture" when Work Order is Completed.

cancel consumption validation

Notes

  • Please help test, write feedbacks and report issues.
  • Test Case Creation is on going.
  • Documentation will be after Alternative BOM line and Work Order renaming Documentation is done.

@creamdory creamdory requested a review from nabinhait March 24, 2018 09:32
@creamdory creamdory changed the title Work Order Material Consumption [Enhancement] Work Order Material Consumption Mar 24, 2018
@dottenbr
Copy link
Copy Markdown
Contributor

Let me quickly explain why we didn’t yet contribute documentation on this.

We have not updated the documentation since the Frappe team is working on that currently due to the Production Order to Work Order transition. Whoever works on that could include this in the documentation if the design gets accepted or we can contribute the documentation after the updated documentation is available.

@dottenbr
Copy link
Copy Markdown
Contributor

Could you let us know if there is anything you need from us to get the PR merged ASAP? We are on a tight schedule. We are migrating on Friday this week and need this in.

@creamdory creamdory force-pushed the material_consumption branch from 452c533 to 1041ac5 Compare March 26, 2018 06:39
@creamdory
Copy link
Copy Markdown
Contributor Author

creamdory commented Mar 26, 2018

@nabinhait we bumped into an issue with this design since it records "issuance" accounting in the new purpose "Material Consumption for Manufacture". This creates a problem in making/calculating Valuation Rate of the Finish product.

Can you suggest how to proceed so we can change code right away? Issue was pointed out in this discuss post https://discuss.erpnext.com/t/material-consumption-for-manufacture/35076.

@creamdory
Copy link
Copy Markdown
Contributor Author

creamdory commented Mar 26, 2018

@nabinhait , here is my suggestion. We should have the idea of recording "WIP" accounts.

So in the current design, we have these accounting entries for direct material:

"Manufacture" Stock Entry:

DEBIT: Finish Goods $ 1.00
CREDIT: Components $ 1.00

If we will be adding the idea of "Material Consumption for Manufacture", we can have these accounting entries:

"Material Consumption for Manufacture" Stock Entry:

DEBIT: WIP Direct Material $ 1.00
CREDIT: Components $ 1.00

"Manufacture" Stock Entry:

DEBIT: Finish Goods $ 1.00
CREDIT: WIP Direct Material $ 1.00

OR

"Manufacture" Stock Entry:

DEBIT: Finish Goods $ 1.00
CREDIT: WIP Direct Material $ 0.50
Components $ 0.50

So the components will be exhausted during the consumption using a WIP account. This means that we need to allow the "Manufacture" stock entry to record the "WIP" cost and use this to calculate the finish good's valuation rate. The WIP accounts should also show in the Balance sheet. We can add a column/field in the "Company" doctype as "WIP Direct Material" account to set-up the default account for this scenario. Same is true with Direct Material.

Let us know what you think.

@djpalshikar
Copy link
Copy Markdown
Contributor

djpalshikar commented Mar 26, 2018

Doesn't allow consumption more than Transferred Qty.

Currently if the WIP warehouse has enough stock, "Finishing is allowed", is there is specific reason why you would like to disallow consumption ?

We should have the idea of recording "WIP" accounts.

Can you should how the stock ledger will look like after consumption and completion?

@creamdory
Copy link
Copy Markdown
Contributor Author

@djpalshikar can you pls put feedback from my recent suggestion about WIP accounts?

@creamdory
Copy link
Copy Markdown
Contributor Author

creamdory commented Mar 26, 2018

@djpalshikar

Currently if the WIP warehouse enough stock, "Finishing is allowed", is there is specific reason why you would like to disallow consumption ?

This is the idea. If the WIP has enough stock it can consume. But if WIP only has 50 and consumption is 60 then this is not allowed.

We should have the idea of recording "WIP" accounts.

In my recent comment, you can look at the accounting entries. For the Stock Ledger, here it is:

"Material Consumption for Manufacture" Stock Entry

screen shot 2018-03-26 at 12 48 59

"Manufacture" Stock Entry

screen shot 2018-03-26 at 12 49 25

For partial consumption with "Manufacture" Stock Entry

"Material Consumption for Manufacture"

screen shot 2018-03-26 at 12 49 57

"Manufacture" Stock Entry

screen shot 2018-03-26 at 12 50 16

@djpalshikar
Copy link
Copy Markdown
Contributor

djpalshikar commented Mar 26, 2018

@creamdory

  • After consumption entry, Value of WIP Stock will go down by $1. And nothing else will be affected.
    Although value of Stock at WIP is still the same. This could be an issue.

  • For users having Perpetual accounting enabled, I think you have got it right. But for users where accounting is not perpetual, they will have to manually take care of "Consumption Entries" and create a ledger.

  • Lastly someone from Frappe has to clarify if this will affect how Valuation Rate is calculated for items The article here https://frappe.erpnext.com/kb/stock/how-valuation-rate-is-calculated-for-an-item is silent on "Stock Entry for Manufacture"

@nabinhait
Copy link
Copy Markdown
Member

nabinhait commented Mar 26, 2018

Regarding accounting entry for "Material Consumption for Manufacture", let leave it to the users. Basically, user should be able to enter "Difference Account" manually and it can be either expense or asset account.
BY default, I will suggest to skip accounting entries for "Material Consumption for Manufacture". So, to do that we will set "Difference Account" as the WIP warehouse account. Hence, the system debit and credit the same account and resulting no accounting entries. And in "Manufacture" entry as well, we will set "Difference Account" as WIP warehouse. So, system will debit FG Warehouse account and credit WIP warehouse account.
If the user want to book expense while consumption, they can change it to "Cost of Goods Sold" account or any other.
If the user want to maintain another intermediate asset account, they can manually select that account in the consumption entry.

if self.work_order and self.purpose == "Material Consumption for Manufacture":
self.validate_work_order_status()
else:
self.update_stock_ledger()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update_stock_ledger should be outside else condition.

if self.purpose in manufacture_purpose and self.work_order:
if not frappe.get_value('Work Order', self.work_order, 'skip_transfer'):
item_code = []
for item in self.items:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop should only be run for raw materials. Add a if condition if cstr(item.t_warehouse) = '':

if stock_qty > trans_qty:
item_code.append(item.item_code)
if item_code:
frappe.throw(_("Consumption quantity cannot be more than transferred quantity for item/s {0}.").format(', '.join(item_code)), OverConsumptionError)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do this validation? Because many cases, some unused raw materials (from earlier Work Orders) are there in WIP warehouse, which gets used. And it can lead to more consumption than transferred qty.

if (self.purpose == "Material Consumption for Manufacture" or self.purpose == "Manufacture"):
for items in self.items:
if self.docstatus == 1:
frappe.db.sql("""Update `tabWork Order Item` set consumed_qty = consumed_qty + %s
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always avoid codes like this which does "+" and "- for updating qty. Use sum of all consumed qty against the work order, similar to https://github.com/frappe/erpnext/blob/develop/erpnext/manufacturing/doctype/work_order/work_order.py#L498

@creamdory
Copy link
Copy Markdown
Contributor Author

creamdory commented Mar 26, 2018

@nabinhait , what about the calculation of the Finish product valuation rate ?

Also, I wanted to confirm to you this:

I will suggest to skip accounting entries for "Material Consumption for Manufacture". So, to do that we will set "Difference Account" as the WIP warehouse account.

This means the stock is consumed and deducted in the system but with zero accounting entries? And how do we make all the entries during finish? Should we get component cost from all the "Material Consumption for manufacture" for a work order?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some docstrings in this whole calculation, to explain the use case?

@nabinhait
Copy link
Copy Markdown
Member

nabinhait commented Mar 26, 2018

This means the stock is consumed and deducted in the system but with zero accounting entries? And how do we make all the entries during finish? Should we get component cost from all the "Material Consumption for manufacture" for a work order?

Yes, it will not going to work, it is not that simple. What about if we book normal expenses while consumptions? And while updating finished goods, raw material expenses will be reverted, if we use same difference account. And expenses will be booked only for additional costs.
Now, the main challenge is updating valuation rate for FG item. Even if take consumed material costs, we don't know against how many FG items, those raw materials are consumed.

@creamdory creamdory force-pushed the material_consumption branch from adb0791 to 0fc10b0 Compare March 26, 2018 14:38
@creamdory
Copy link
Copy Markdown
Contributor Author

@nabinhait , made the changes you requested. And about below:

Yes, it will not going to work, it is not that simple. What about if we book normal expenses while consumptions?

Currently, it is done like this now. "Material Consumption for Manufacture" behaves like a "Material Issue" only with tagged Work Order.

And while updating finished goods, raw material expenses will be reverted, if we use same difference account. And expenses will be booked only for additional costs. Now, the main challenge is updating valuation rate for FG item. Even if it take consumed material costs, we don't know against how many FG items, those raw materials are consumed.

Can't be done since there is an option to do consumption in the "Manufacture" stock entry too when booked "Material Consumption for manufacture" is not done fully for the fg_completed_qty. And yes it will be challenging in the valuation rate calculation that is why I have suggested a WIP account that will be reverted in the "Manufacture" stock entry.

@nabinhait
Copy link
Copy Markdown
Member

nabinhait commented Mar 27, 2018

@dottenbr @creamdory Documentation is updated for renaming Production Order to Work Order. You can start documenting this changes.

Copy link
Copy Markdown
Member

@nabinhait nabinhait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire functionality should be hidden by default. And can be enabled via a setting in Manufacturing Settings.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same calculation is applicable if "Backflush Raw Materials Based On" is set as "BOM" in Manufacturing Settings. It should consider Consumption entry and pull only remaining items.

Copy link
Copy Markdown
Contributor Author

@creamdory creamdory Mar 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nabinhait this is what this code do.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think it does not work if "Backflush Raw Materials Based On" is set as "BOM" in Manufacturing Settings. I think get_transfered_raw_materials is not called for that use case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not be shown if all items are consumed

@creamdory creamdory force-pushed the material_consumption branch from 0fc10b0 to dd39201 Compare March 28, 2018 08:18
@creamdory creamdory force-pushed the material_consumption branch 3 times, most recently from dccf9c8 to 53068a6 Compare March 28, 2018 10:21
@creamdory
Copy link
Copy Markdown
Contributor Author

@nabinhait

Material Consumption in "Manufacturing Settings"
screen shot 2018-03-28 at 12 24 15

screen shot 2018-03-28 at 12 26 57

consumption

@nabinhait
Copy link
Copy Markdown
Member

@creamdory Change the label "Material Consumption" to "Allow Multiple Material Consumption".

@creamdory creamdory force-pushed the material_consumption branch from 53068a6 to 0894896 Compare March 28, 2018 11:57
@creamdory
Copy link
Copy Markdown
Contributor Author

@nabinhait

screen shot 2018-03-28 at 13 57 46

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nabinhait Added this to trigger get_transfered_raw_materials() without looking at the backlash_raw_materials_base_on

Copy link
Copy Markdown
Member

@nabinhait nabinhait Mar 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@creamdory It is not right. If "backflush_raw_materials_based_on" is based on BOM, then it should not consider transferred materials. It will simply assume all the items in the BOM is in WIP warehouses.

@creamdory creamdory force-pushed the material_consumption branch 3 times, most recently from 47864ca to 381e0e4 Compare March 29, 2018 12:03
@creamdory
Copy link
Copy Markdown
Contributor Author

@nabinhait requested changes made.

@creamdory creamdory force-pushed the material_consumption branch 2 times, most recently from 3b342b7 to 1988562 Compare March 29, 2018 13:08
@creamdory
Copy link
Copy Markdown
Contributor Author

@nabinhait currently, documentation is broken. https://discuss.frappe.io/t/bug-documentation-broken/601

@creamdory creamdory force-pushed the material_consumption branch from 1988562 to 98bcffe Compare March 29, 2018 15:24
@creamdory
Copy link
Copy Markdown
Contributor Author

@nabinhait made the documentation. Please check.

@nabinhait nabinhait merged commit ad76f9a into frappe:develop Apr 9, 2018
@djpalshikar
Copy link
Copy Markdown
Contributor

djpalshikar commented Apr 9, 2018

@creamdory is there decision on the valuation of the finished item ?

@creamdory
Copy link
Copy Markdown
Contributor Author

@djpalshikar currently not automated. Nabin says to change accounts during Stock Entries. Though we will think about it and make some enhancements. Currently, this feature can be enabled or disabled for this case.

@dottenbr dottenbr deleted the material_consumption branch October 25, 2018 06:00
ashish-greycube added a commit to ashish-greycube/erpnext that referenced this pull request Feb 10, 2020
…acture

Hi @nabinhait ,
 
Issue : Manufacturing setting > Backflush Raw Material Based on “Material Transferred for Manufacture” doesn't fetch the actual raw material transferred qty. It fetches qty based on "BOM"

The issue is because @creamdory in PR #frappe#13384
commit : https://github.com/frappe/erpnext/pull/13384/files#diff-91f0ed661ef4b6e1f167fc7961b1a79b

```
changed from: if trans_qty and manufacturing_qty >= (produced_qty + flt(self.fg_completed_qty)):
to : if trans_qty and manufacturing_qty > (produced_qty + flt(self.fg_completed_qty)):
```
**'='** was added by her in the condition, which was not there before her commit.
Kindly except the fix for the issue.


https://github.com/frappe/erpnext/blob/develop/erpnext/stock/doctype/stock_entry/stock_entry.py#L1057

frappe#13384

https://github.com/frappe/erpnext/pull/13384/files#diff-91f0ed661ef4b6e1f167fc7961b1a79b

**before fix gif** :  Stock Entry = Manufacture shows raw material quantity as per BOM.

![FetchTransQtyError](https://user-images.githubusercontent.com/29812965/74123824-ffdd8600-4bf5-11ea-8873-95de24a7ef09.gif)

**after fix gi**f :  Stock Entry = "Manufacture" shows raw material quantity as per "Material Transfer for Manufacture".

![FetchTransQtyFix](https://user-images.githubusercontent.com/29812965/74123836-0c61de80-4bf6-11ea-86fb-d9619fd9b02b.gif)
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants