frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)
https://erpnext.com
GNU General Public License v3.0
20.95k stars 7.19k forks source link

Default batch number selection #10562

Closed ajinkyagadewar closed 6 years ago

ajinkyagadewar commented 7 years ago

How can we use the FIFO method for batch number while doing the sales invoice?

Current Scenario: In case of Pharma/FMCG vertical, complete purchase and sales is dependent on batch and expiry date. Currently, ERPNext have the provision to setup batch number against each item while receiving the product. So from purchase perspective this is good. While doing sales invoice, we have to manually select the batch and add the quantity in it.

Expected Scenario: While doing the sales invoice, item should automatically fetch the batches as per FIFO method. In case if the first available batch have less quantity it should pickup next available batch and so on.

Can we do this?

ajinkyagadewar commented 6 years ago

Any timelines on this issue?

mdwala commented 6 years ago

Hi @ajinkyagadewar Happy to see you using ERPNext in Pharma business. We are also in business of diets which has expiry and batches, and other business of wholesale medicine(pharmacy). My personal view is (unfortunately) there isn't much concentration from any contributors & core team and also not many users using "Has Batch No" items, these can be main reasons for not much improvements anything related to "Batch No". I couldn’t convince one party to go for ERPNext cloud once they found out by using free account, of these things about not auto selecting batches. For your reference other issue related to batch 11004 11003 9643 8714

Let's feel sad together :(

tundebabzy commented 6 years ago

@mdwala , @ajinkyagadewar What is the correct way to treat this situation from the Sales Invoice: Batch A has 1 unit of item X remaining and Batch B has 100 units of item X remaining. An invoice is to be raised for 50 units of Item X. What batch number should be auto-fetched?

DavidMenting commented 6 years ago

I think @ajinkyagadewar sketched the desired behavior in his issue already: "In case if the first available batch have less quantity it should pickup next available batch and so on."

The oldest batch with enough units to fulfil the requirement should be picked, in this case Batch B.

tundebabzy commented 6 years ago

Oh OK. Thanjs

mdwala commented 6 years ago

Hi @tundebabzy @DavidMenting @ajinkyagadewar On case @tundebabzy asked, if only one expiry for both batches than FIFO (First In First Out) can work.

But if both batches have different expiry dates, then it should follow FEFO (First Expire First Out) with no relation of which one purchased earlier or after. Expiry date is all we needs to worry about.

If First expiry batch is not having sufficient quantity it should (auto) pick rest quantity from next expiry batches.

tundebabzy commented 6 years ago

Ok then. So the workflow we be something like:

If: Item has expiry date, return oldest batch with sufficient quantity and soonest expiry date else if: return oldest batch with sufficient quantity else: return blank

mdwala commented 6 years ago

@tundebabzy "Sufficient quantity" is overkill. As a supplier and retailer in Diet Food & Medicine business, if we don't have sufficient quantity in first expiring batch, we give whatever quantities we can give from first expiring batch, and then rest from 2nd expiring batch ...and follows... If we wants to give single batch for all quantity, we change as per our need (which gives another requirement of having field in Sales Invoice Item table "remaining batch qty")

tundebabzy commented 6 years ago

@mdwala There is only one field for batch number. While we can have another field for remaining_batch but what if the order consumes 3 batches, or 4 or 5?

tundebabzy commented 6 years ago

Ok. I see that there can be multiple batches in the POS. I'll investigate that

DavidMenting commented 6 years ago

These are actually two separate issues. I think, having automatic batch selection of a batch of sufficient size is already very useful and shouldn't be too hard to implement.

tundebabzy commented 6 years ago

These are actually two separate issues. I think, having automatic batch selection of a batch of sufficient size is already very useful and shouldn't be too hard to implement.

Yeah. And quite important too. I'll be implementing the automatic batch selection of a single batch number using 'FEFO' for non-POS Sales Invoice. When I'm through with that, I'll investigate the POS

mdwala commented 6 years ago

@tundebabzy @DavidMenting To clear:

By the way forgot to say thanks @tundebabzy for your input on this dead issue. Didn't expect that!

Thanks again......

tundebabzy commented 6 years ago

@mdwala It seems we are talking about a different scenario from the issue raised in the ticket. Can you open a fresh issue or direct me to a similar one so that we can continue discussing from there.

mdwala commented 6 years ago

Did earlier 11004 But no one responded it. No issue, I will leave this here.

hpema commented 6 years ago

Hi Folks,

We are using a similar concept called LOT at our company. Im not familier of how this works in your industry but we are using LOT (Batch) to control costs. Currently the incoming price and outgoing price of an item that has a batch in erpnext is different. I logged a ticket https://github.com/frappe/erpnext/issues/7191 that describes the use case and I think there are some changes since then.

I have tested the serialised items in v9 and the costs are correctly recorded based on the serial number picked. So I have done a test where I receive item at 3 difference prices. And no matter which item I deliver if I pick the correct serial number then the ourgoing cost will match the incoming cost.

I think a slight adjustment in the current operation can greatly enhance erpnext. I tried but am still struggling to find the right way to code this - and also afraid to break something.

I think if we can allow a series to be created like in serial number and the number gets generated automatically then that makes picking the lots a little easier to read by the picker of stock when delivery is generated.

To fullfil the quantity issue we can just allow the user to select more then one lot to fullfil the order.

Hope my rambling is not confusing anyone ;)

My goal is that when we receive stock a lot and cost is associated to all stock movement - incoming and outgoing. This cost is what the all the ledger transactions will use.

If I can get guidance on what to change and look into to learn more how the general ledger is generated I can try to get this done - but its been almost a year and I still struggle to figure out the code (not doing this full time so)....

I hope im making sense.

regards

tundebabzy commented 6 years ago

@hpema Your suggestion is interesting. Please can you add your comment to #7191 since it's related to it. Once I close this out, I'll pick it up.

tundebabzy commented 6 years ago

While doing the sales invoice, item should automatically fetch the batches as per FIFO method. In case if the first available batch have less quantity it should pickup next available batch and so on.

Can we do this?

Done by #11454. ERPNext will use FEFO (First Expiring First Out) which is like FIFO just that the soonest to expire will be picked first even if it's the last to come in.

tundebabzy commented 6 years ago

@ajinkyagadewar also take note that except "Update Stock" is checked in the Sales Invoice, the batch number will not be fetched

ajinkyagadewar commented 6 years ago

Understood. Thanks.

mobentec commented 6 years ago

@tundebabzy With v10, is it still not possible to include multiple batches of a single item within one Delivery Note?

If not, are there any plans to allow for creating Delivery Notes that details the correct item quantity (as dictated by the Sales Order), however also show the associated mixed of batches that are being allocated to that Sales Order/Sales Invoice/Delivery Note/Customer?

tundebabzy commented 6 years ago

At the moment there is none. Please open a new issue to request for this.