Event Streaming enables inter site communications between two or more sites. You can subscribe to Document Types and stream Documents between different sites.
For Example: Consider you have more than one Company hosted on different sites, one among them is the main site where you want to do ledger posting and on other sites, the Sales Invoices are generated. You can use Event Streaming in this case. For this, your child company sites can subscribe to the main company site for Item, Customer, and Supplier Document Types. The main Company in turn can subscribe to the child companies for Sales Invoices.
To access Event Streaming, go to:
Home > Automation > Event Streaming
Before creating an Event Producer, a common user needs to be created on both the sites which will be used to access the site and will act as an Event Subscriber. Make sure the user is a System Manager and has the necessary permissions for creation, updation, and deletion of the subscribed DocTypes.
Let's take two sites for explaining the process. http://test_site:8000 (Consumer site) and http://test_site_producer:8000 (Producer site)
On http://test_site:8000 (consumer site), go to the User list and follow the same process specified in the previous step.
Note: If at all the API Secret is changed for the users on any of these sites, you will have to manually update the keys in the Event Producer as well as the Event Consumer on both the sites.
Note: Document updates for Subscribed Document Types won't be synced unless they are Approved.
If you have some places where internet connectivity is low, for example, a store in a remote area where sales invoices are generated and you want to sync these invoices from the store to the hosted account, you could setup offline syncing using the following steps:
As an Event Consumer, if you wish to unsubscribe from the updates for any doctypes you had previously subscribed to, check unsubscribe against the doctype. You will not receive any more updates from the producer site for that particular doctype once you have unsubscribed.
"Event Update Log" logs every create, update, and delete action for documents that have consumers on the Event Producer site. In order to view the Event Update Log:
Go to: Home > Automation > Event Streaming > Event Update Log.
Like the Update Log, Event Sync Log logs every document synced from the Event Producer on the Event Consumer site. In order to view the Event Sync Log:
Go to: Home > Automation > Event Streaming > Event Sync Log.
A successfully synced event generates a log document with:
A failed event generates a log doc with the above fields along with:
Certain Document Types have dependencies. For example, before syncing a Sales Invoice, the Item and Customer need to be present in the current site. So, Item and Customer are dependencies for Sales Invoice. Event Streaming handles this by on-demand dependency syncing. Whenever any document is to be synced, it first checks whether the document has any dependencies (Link fields, Dynamic Link fields, Child Table fields, etc.). If that dependency is not fullfilled i.e. the dependent document (eg: Item) is not present on your consumer site, it will be synced first and then the Sales Invoice will be synced.
For example: Sales Invoice syncing with Item dependency:
Check the 'Use Same Name' checkbox to let the documents have same name on both Event Producer and Event Consumer sites. If this is not checked, then the document will be created using the naming conventions of the current site.
Note: For Document Types that have naming series, it is advised to keep the 'Use Same Name' checkbox unchecked, to prevent naming conflicts. If this is unchecked, the Documents are created by following the naming conventions on the current site and the 'Remote Site Name' and 'Remote Document Name' custom fields are set in the synced document to store the Event Producer site URL and the document name on the remote site respectively.
If you want to stream documents between two OneOfficeERP instances for a particular Document Type with same or different structures, or if field names are different in both the sites, you can use Event Streaming with Mapping Configuration.
For this you need to first set up a Document Type Mapping.
To access Document Type Mapping, go to:
Home > Automation > Event Streaming > Document Type Mapping.
In the Field Mapping child table:
If your field is not mapped to any other remote fieldname and you always want the field to have the same value, set the set the same in the default value field. Event if you have set the remote fieldname, in case during the sync, remote field's value is not found and if the "Default Value" has been specified, it will be set.
If the field you are trying to map is a child table, you need to create another Document Type Mapping for the child table fields.
If the DocTypes you are trying to map have any kind of dependencies like Link or Dynamic Link fields, you need to set up another Document Type Mapping for syncing the dependencies.
For example, let's assume that the local doctype is Opportunity and the remote doctype is OneOfficeERP Opportunity. The field party_name
(Link field for DocType Lead) in Opportunity is mapped to full_name
(Data field) in OneOfficeERP Opportunity. During the sync, this Lead has to be created for the main Opportunity to sync. So you need to set up a mapping for this Link Field too.
The format is:
{ "remote fieldname": "field or expression from where we will get the value for that fieldname"}
If you want to fetch the value from somewhere, start the expression with eval:
Like in this case it is: eval:frappe.db.get_value('Global Defaults', None, 'country')
Lastly, enable the 'Has Mapping' option in the Event Configuration child table in Event Producer against the required Document Type and select the Document Type Mapping you just created.
If you are in scenario when you do not want to send over all the documents in a doctype over to the consumer, you can specify the conditions for them.
For example, if you would like to emit only those Note
documents that are public, you can specify them within the Producer/Consumer document.
If a document satisfies a condition down the line in its lifetime, all the old
Event Update Logs
are synced to the consumer
Let's consider another example. You want to sync only those Sales Invoices that are submitted. You can specify doc.docstatus == 1
as the condition. The invoices will not be synced until they are submitted.
For each update log, you can see its Consumers within the Update Log document.
If you need more fine control over the conditions, you can hook up a custom function. Your function will be executed with parameters consumer
, doc
& update_log
. For example, you want to sync only those Notes that are odd
def is_odd_note(consumer, doc, update_log):
return frappe.db.sql("""
SELECT
COUNT(*)
FROM `tabNote`
WHERE creation <= %(creation)s
""", { "creation": doc.creation })[0][0] % 2 != 0
Then, you could specify the condition:
cmd: my_custom_app.note.is_odd_note