i have 2 companies one is trading other is manufacturing, manufacturing company give goods to trading and trading pay to manufacturing both are link as intercompany supplier and customer and purchase and sales are working. i have server side script if trading company make a payment entry the same entry show in manufacturing if manufacturing cancel or delete the entry cancel or delete from trading too. what i want if trading company make a payment then other payment entry should be create in manufacturing in draft
here is my script
if doc.company == “trading” and doc.party_type == “Supplier” and doc.party == “manufacturing”:
frappe.msgprint(“Payment Entry detected in trading for manufacturing.”) # Debugging message
try:
# Create a draft Payment Entry in manufacturing
new_payment = frappe.new_doc("Payment Entry")
new_payment.payment_type = "Receive" # manufacturing will receive this payment
new_payment.company = "manufacturing" # Payment belongs to manufacturing
new_payment.party_type = "Customer" # manufacturing views trading as a customer
new_payment.party = frappe.db.get_value("Customer", {"customer_name": "trading"}, "name") # Fetch linked customer
new_payment.posting_date = doc.posting_date # Same posting date as the original payment
new_payment.paid_amount = doc.paid_amount # Amount paid by trading
new_payment.received_amount = doc.paid_amount # Amount received by manufacturing
new_payment.mode_of_payment = doc.mode_of_payment # Use the same mode of payment
new_payment.reference_no = doc.reference_no # Reference number from the original payment
new_payment.reference_date = doc.reference_date # Reference date from the original payment
new_payment.remarks = f"Auto-created draft Payment Entry from trading Payment Entry {doc.name}"
# Set appropriate accounts
# Update the paid_to field with a valid Bank or Cash account for manufacturing
new_payment.paid_to = frappe.db.get_value("Account", {"account_name": "Bank Account - AYP"}, "name") or "Bank - AYP" # Replace with an actual account name
new_payment.paid_from = frappe.db.get_value("Account", {"account_name": "Debtors - AG"}, "name") # Validate this account exists
# Insert the draft Payment Entry
new_payment.insert(ignore_permissions=True)
frappe.msgprint(f"Draft Payment Entry created in manufacturing: {new_payment.name}")
except Exception as e:
frappe.log_error(f"Error creating Payment Entry in manufacturing: {str(e)}", "Payment Entry Synchronization Error")
frappe.msgprint(f"Error creating Payment Entry in manufacturing: {str(e)}")