Return Invoice - Stock and Accounting

Please advise on how to remove restrictions on Quantity when Return checkbox is selected while creating invoice.

The reason behind that is, the following scenario occurs in real;
Customer placed Order #1 and already paid against Invoice #1 having Item #1 and now customer is asking for replacement with different Item #2 (assuming same price).

Based on the above mentioned restriction, two invoices shall be created,

A) Invoice #2 (return checkbox on) with -ve quantity to handle the return of Item #1.

B) Invoice #3 (return checkbox off) with +ve quantity to handle the sale of Item #2.

The above resolution is good with inventory but causes headache with accounting as no way to clear Invoice #3 on a basis of Mode of Payment as Account Balance (think about customer wallet) as no payment shall be expected from the customer and hence with every return manual Credit Note shall be created to adjust accounting records.

The simple approach is only Invoice #2 just enough to resolve Inventory/Accounting concerns once by adding Item #2 with +ve quantity and Item #1 with -ve quantity and hence Invoice #2 to be paid in status (by assuming same price) or only the net amount to be refelected to payment entry (by assuming higher price for Item #2)

Firstly - In ERPNext the Sales Invoice item is linked to Sales Order (unless you specifically select under settings to not require a sales order). So for most of us you cannot typically invoice items that do not exist on sales order. Seems in your case you are able to invoice new item without creating a sales order.

Secondly - when you do a return on an already paid invoice - there is another setting that allows you to delink the payment entry from the invoice upon cancellation / return. When you issue a new invoice - the customer balance is not affected but the new invoice will show as unpaid. This can be cleared with a payment reconciliation where old payment entry is applied to new invoice.

Sometimes there are payments that are applied to specific invoices and not in order of issue - so setting up a script to run auto payment reconciliation (FIFO say) may not be a blanket solution for all.

I guess the question should be whether there is a way to auto trigger a payment reconciliation for a sales order with an unreconciled payment entry when a new sales invoice is issued… ???

well, I’m not sure about that technically but yes I agree with the concept.

I don’t feel right with link/delink feature cause once the document submitted everything becomes read-only including links.

Even though Payment Entry can be cancelled on erpnext system yet I can’t do that, cause payment has been already processed earlier by customer using wire transfer and hence get it cancelled is going to cause conflicts with account statement by the bank.

Yes, I cope with direct invoicing (from settings) yet I keep Sales Order for customers having partial delivery/payments; however the issue about handling returns comes after.

For future reference for anyone having the same scenario;
Below, were the hacking to bypass the above mentioned issue

			for d in self.get_all_children():
				if hasattr(d, 'qty') and d.qty < 0 and not self.get('is_return'):
					frappe.throw(_("For an item {0}, quantity must be positive number").format(d.item_code))

				if hasattr(d, 'qty') and d.qty > 10 and self.get('is_return'):
					frappe.throw(_("For an item {0}, quantity must be negative number").format(d.item_code))

Original Code Lines

Hi

Can you clarify what the above hack does to solve your problem.

Regards

if hasattr(d, 'qty') and d.qty > 10 and self.get('is_return'):
frappe.throw(_("For an item {0}, quantity must be negative number").format(d.item_code))

The above section takes control when checkbox of is_return is ticked and hence doesn’t accept +ve quantity in all items listed in items table. as the original code states d.qty > 0.

Shifting the validation limit to d.qty > 10 or 100 or 1000 (depends on the common quantities normally dealt with) will allow listing the items table with both -ve and +ve quantity in single invoice.

The stock entries and accounting transactions goes normally after and not affected by the above constraint.