From 8d7c1868d6749b49371d230ce1ffcc89a9b03a57 Mon Sep 17 00:00:00 2001 From: Bassam Ramadan Date: Thu, 30 Aug 2018 15:45:15 +0200 Subject: [PATCH] fix for fields names at sales invoice return payments and verifying the payment amount (#15245) * fix for payments field names in sales invoice return * add verification for payment amount at sales invoice return adding verification to be sure the payment amount is negative at sales invoice return * correction for precision field name --- .../accounts/doctype/sales_invoice/sales_invoice.py | 10 ++++++++++ erpnext/controllers/sales_and_purchase_return.py | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index fd77d4b47e..d74121506e 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -112,6 +112,11 @@ class SalesInvoice(SellingController): self.set_status() if self.is_pos and not self.is_return: self.verify_payment_amount_is_positive() + + #validate amount in mode of payments for returned invoices for pos must be negative + if self.is_pos and self.is_return: + self.verify_payment_amount_is_negative() + if self.redeem_loyalty_points and self.loyalty_program and self.loyalty_points: validate_loyalty_points(self, self.loyalty_points) @@ -971,6 +976,11 @@ class SalesInvoice(SellingController): if entry.amount < 0: frappe.throw(_("Row #{0} (Payment Table): Amount must be positive").format(entry.idx)) + def verify_payment_amount_is_negative(self): + for entry in self.payments: + if entry.amount > 0: + frappe.throw(_("Row #{0} (Payment Table): Amount must be negative").format(entry.idx)) + # collection of the loyalty points, create the ledger entry for that. def make_loyalty_point_entry(self): returned_amount = self.get_returned_amount() diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index 43d820ff39..d0f3ccd2c8 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -232,8 +232,8 @@ def make_return_doc(doctype, source_name, target_doc=None): doc.append('payments', { 'mode_of_payment': data.mode_of_payment, 'type': data.type, - 'paid_amount': -1 * paid_amount, - 'base_paid_amount': -1 * base_paid_amount + 'amount': -1 * paid_amount, + 'base_amount': -1 * base_paid_amount }) elif doc.doctype == 'Purchase Invoice': doc.paid_amount = -1 * source.paid_amount