We are faced with a integration Scenario where we need to integrate a intended ERPNext system with a external automated manufacturing system which produced serialized Items. The manufactured Items will have, beside the serial number self, a couple of other serialized identifier like asset codes, initial Login user, MAC addreses etc. The Integratiion will happen via a SOAP based request/response API. And will also required status polling against a manufacturing order. The manufactured Items need to be ordered in batches as there is a MoQ against the items. The order Items will go to a stock of a warehouse once arrived. After a sales order arrives the Items need to be bundled with a service product (which will instantiate a recurring service contract later) and sold to the customer. The Sales Process should create a made to order (after payment) manufacturing of a BOM containing the stocked, purchased item and the service Item.
Based on a rough analysis of the capabilities the described process could be modeled with a existing ERPnext capabilities of:
- Item to be purchased or subcontract manufacured
- Service Items
- Sales Item which has BOM of the two items above
- Purchase or Subcontract Item manufacturing with the external system
- Made to order payment process
- Shopping cart collecting the consumer orders of the bundled sales Item
It seems everything would have proper transaction documents for external purchase,
manufacturing and so on.
so far so (hopefully) good.
The remaining question for me is: How to automate the process of a give state transaction?
There are a couple of automated process required to run based on certain event, workflow definitions and states or transactions in the system. namely:
- a purchase order (PO) against the manufacturer should call the external API to order the goods i.e. 200 pieces
the process will be monitored and after a while the serial numbers and asset IDs etc. will be available in the API and need to be imported i.e. against a Purchase Receipt. The PO might be triggered manually by a ERP next Stockist user role
- a PO as described above might be triggered automatically based on a low stock trigger and the process of calling the API must be triggered automatically. Hence the receive process against PR as well,
- Once a consumer orders the bundled sales item via shopping cart a made-to-order process needs to start which will bundle the serialzed Item with a Service (contract) Item. This manufacturing Process should run automatically and must call a API to activate the given Service against a activation API.
From what I understand the ERPnext based transactions are created already internally in the databases. My question would be how to glue a external process (Calling the APIs) with the manufacturing or purchase transactions. And how to automatically run them based on the workflow definitions.
Can you please advise how to integrate this in a ERPnext idiomatic way? Is the already something like a Workflow engine triggering such API calls?
May thanks, and obviously everything which might be required would become open source and could be handled as a bounty to some one will help
@hwinkel From what I see, you will have to build those extensions yourself in a separate app. I am sure you can find devs in the community (https://community.erpnext.com/jobs) who would be happy to help you.
If there are generic parts, please contribute them back
Generally in regards to automating workflow:
Personally this is the process I used to automate workflow:
- Write down and try out the explicit workflow you’re trying to automate. You will have to do the workflow multiple times by hand to learn what documents are generated and what information is needed. In the end this should look like a flowchart.
- For each step in your workflow find out which functions are being called with each button press. You will find these functions mostly in the $module/doctype/$doctype/$doctype.(py|js) files (e.g. selling/doctype/sales_order/sales_order.py) Most important here is understanding how ERPNext pre-fills certain documents and what mandatory fields you have to fill yourself. Later you will leverage these functions to automatically generate and fill the documents in your workflow.
- Now it’s time to automate. I personally would advise you write your code in a new app which you then also install on the erpnext site, but you can also write your code anywhere you want, but the app you’re writing in must be installed on the same site as erpnext. If you did the first two steps thoroughly you will already have a good understanding of what needs to be done, for general implementation examples you should look at the code. almost all the stuff you’ll need is already used in the files described above. I also found these three pages (hooks, database, document) from the API docs very helpful.
In this specific case:
- You can write a function, which gets called on the on_submit hook of the PO, which then sends this external API request. To then import the results of this order you will most likely create multiple documents (frappe.new_doc(doctype)). First, for every serial number a new serial number document, and second a stock entry, with the purchase purpose, so you can add the goods to your stock.
- ERPNext already comes with a auto-reorder function for stock-items. When your stock is lower than the set reorder-level a material request is automatically generated. You can use a hook to “catch” this document creation and then use the workflow from step one.
- You can automate this workflow starting at the purchase order, then you create a material request for the manufacturing, then you create the production order. In finishing this production order you can make your API-activation call, the result is a fully documented production process inside erpnext and an activated product, ready to be delivered.
If you want to automate a specific workflow, find out what erpnext does (in theory and in code) and what it expects from you to do and then just imitate as best as you can.
The demo of drop shipping
has a couple of good examples where automated execution could be valuabel. I.e. to Start the PO to the supplier automatically once the order for a drop ship item arrives?
my understandig was that the workflow already defines the flow of the documents from step to step like described in the worflow features.
the idas is to automate the defined workflow.
As I understand ERPNext’s workflow it’s primarily meant to add custom states to one document and describing how this state changes. Sadly it doesn’t help in describing changes between multiple documents. Maybe I’m mistaken, but I found it to be not really helpful in automating whole processes. Surely you could rewrite the inner workings of this feature although I would recommend to just use the already working hook system.
Would be good to see how it works in practice. Is there any repo or PR?
@fiesensee thanks for clarification about the Workflow scope. Thats exactly clarifies the current capabilities of ERPnext for me. And validates my impression while using ERPnext that orchestration across different doctypes is mainly a manual process in ERPnext needs to be done my the user. There are helpers due to the links beween documents or the Next Step Options like Copy from → other doctype.
This does not mean its a bad thing, because the functionality is not there at all but we already have hooks for events leaves the automatic workflow open for a external App or NEw to introduce functionality based on a workflow or job execution engine is acting on behalf of a user.
What we have today:
- Hooks for Document Changes which can be seen as a event
- a Job Scheduler uns time based which can emmit events too
- a API which can manipulate Content and State of a DocType
- Transaction DocTypes which document the changes while runnning transaction i.e. a stock move
From a workflow execution perspective it would be good to have the following Funtionality:
- a workflow execution engine which follows a formally described workflow acting like a user the workflow self could be a doctype?
- a Doctype documenting the steps done?
- may a way to revert the transactions?
- glue between a hooks and integration broker defining which API should be called
Such a enige could be internal or even a total external system. Given the fully integrated nature of ERPnext it would better integrated leveraging the existing capabilities
In the particular example. @fiesensee rather then make multiple transaction for “importing” the data i might be looking for existing transactions doing the intended job, even it performed manaually. I.e. The Import of the ordered good could be modelled with a “purchase receipt” (in german Wareneingang ?) or similar. Sketched like this:
- Running Stock Empty → Create PO
- Send PO by SOAP (rather then email or post)
- SOAP adapter polls and waits for results as async process
- Results arrive SOAP Adapter creates a Purchase Receipt with the given content
- Stock will be maintained based on PR which records the transactions
Purchase Process finished. In the Same way the other processes can be modelled.
I agree, a real automation/job execution engine would be an immensely helpful addition to the Frappé framefork. While searching for an already established solution for this, i found this blog post, which seems to suggest that discipline and maintaining a document for every action and transaction is more important than automating certain tasks.
Employees will initially believe that using software is taking longer time in feeding data into system. But they mostly fail to envision benefits of investing that extra effort. ERP application should not be looked as a tool which puts business on auto-pilot mode.
I don’t exactly disagree, but nevertheless I think a good and clean way to automate certain processes could send Frappé to the next level.
Maybe @rmehta and the other guys from Frappé could sponsor development for such a feature?
Here is also a code example to look at regarding the current state of automating ERPNext.
Before sponsoring, I think there needs to be a clarity on what do you mean by “automation” there are many ways of automation - each has a specific use case.
I have made a ink to the Subscription Functionality as this could be build with automated workflows too.