Automating Expiry Date Transfer in Empress Sales Invoice

Introduction

Empress is designed to help you streamline your business processes. One of the ways it does this is by allowing you to create custom scripts to automate tasks. In this guide, we will walk you through creating a custom script to fetch the Expiry Date field from the Batch field to the Sales Invoice Item table. This way, you can ensure that the expiry date information is accurately reflected in the sales invoice items, enhancing data consistency and reducing the need for manual data entry.

Creating a Custom Script for Sales Invoice

To get started, you’ll need to create a custom script for the Sales Invoice. This acts as the parent field in our script.

Writing and Saving the Script

Once you’ve done that, you’ll need to write and save the following script using your favorite text editor:

frappe.ui.form.on("Sales Invoice Item", "batch_no", function(frm, cdt, cdn) {
    var d = locals[cdt][cdn];
        frappe.db.get_value("Batch", {"name": d.batch_no}, "expiry_date", function(value) {
            d.expiry_date = value.expiry_date;
        });
});

In this script, we’re using the frappe.ui.form.on method to trigger a function each time the batch_no field in the “Sales Invoice Item” form is updated. The function fetches the expiry_date field from the Batch field and assigns it to the expiry_date property of the current row in the Sales Invoice Item table.

This script ensures that the expiry date from the Batch field is automatically reflected in the Sales Invoice Item table whenever the batch number is updated. This maintains data consistency and reduces the need for manual data entry.

Please remember to refrain from modifying any part of this code without a complete understanding of its function. Changing any part of the code could result in errors or malfunctioning scripts.

Conclusion

By following this guide, you can ensure that the expiry date information from the Batch field is accurately reflected in the Sales Invoice Item table in Empress, improving data consistency and reducing manual input. This script is just one of the many ways Empress can be customized to better meet your business needs. If you have any further questions or need assistance with other features in Empress, please refer to our other user-friendly guides and resources.