Hi everyone,
I’m working on an ERP system using Frappe, and I’m facing an issue related to updating the debt fields in the “Proveedores de Productos” and “Proveedores de Envios” DocTypes after a purchase is made.
Here’s a breakdown of the situation:
Context:
- “Compras en Masa” (Bulk Purchase) DocType is where we register purchases. It contains:
- A link field to “Proveedores de Productos” (Product Suppliers).
- A link field to “Proveedores de Envíos” (Shipping Suppliers).
- Two fields:
total_productos
(total cost of purchased products) andtotal_envio
(shipping cost).
- In “Proveedores de Productos” and “Proveedores de Envíos”, there’s a “deuda” (debt) field where we want to keep track of the outstanding debt for each supplier.
Problem:
When a purchase is made, I want the debt field in “Proveedores de Productos” to be updated with the total amount from total_productos
and the debt field in “Proveedores de Envíos” to be updated with the total_envio
value.
- For “Proveedores de Productos”, the debt should increase by the total amount of products bought from that supplier.
- For “Proveedores de Envíos”, the debt should increase by the shipping cost associated with the purchase.
What I’ve Tried:
I attempted to do this using Client Scripts in Frappe, but the debts are not updating as expected. I’ve used a frappe.call
method to try to update the debt fields by fetching the supplier documents and updating the “deuda” field, but nothing happens after the purchase is submitted.
Here’s an overview of what I am currently trying (simplified):
frappe.ui.form.on(‘Compras en Masa’, {
on_submit: function(frm) {
// Get the suppliers and debt values
const proveedor_productos = frm.doc.proveedor_productos;
const proveedor_envios = frm.doc.proveedor_envios;
const deuda_productos = frm.doc.total_productos || 0;
const deuda_envios = frm.doc.total_envio || 0;
// Update the debt for each supplier
if (proveedor_productos) {
frappe.call({
method: "frappe.client.set_value",
args: {
doctype: "Proveedores de Productos",
name: proveedor_productos,
fieldname: "deuda",
value: deuda_productos
}
});
}
if (proveedor_envios) {
frappe.call({
method: "frappe.client.set_value",
args: {
doctype: "Proveedores de Envíos",
name: proveedor_envios,
fieldname: "deuda",
value: deuda_envios
}
});
}
}
});
Issues:
- The debt fields are not being updated after the purchase is submitted.
- I’m not sure if there’s an issue with how I’m calling the
frappe.client.set_value
method, or if I need to use another method like Server Scripts or Hooks to make sure the debt is updated properly.
Questions:
- Am I using the correct approach to update the debt fields in the “Proveedores de Productos” and “Proveedores de Envíos” DocTypes?
- Should I be using Server Scripts or some other method instead of Client Scripts for this?
- Is there anything I’m missing in my code or setup that would cause the debt fields not to update?
Any help or suggestions would be much appreciated!
Thanks in advance!