diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 49af1c0c2c..b28911edef 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -223,8 +223,15 @@ class SalesInvoice(SellingController): self.set_paid_amount() def set_paid_amount(self): + paid_amount = 0.0 + base_paid_amount = 0.0 for data in self.payments: data.base_amount = flt(data.amount*self.conversion_rate, self.precision("base_paid_amount")) + paid_amount += data.amount + base_paid_amount += data.base_amount + + self.paid_amount = paid_amount + self.base_paid_amount = base_paid_amount def validate_time_sheets_are_submitted(self): for data in self.timesheets: diff --git a/erpnext/patches/v7_0/repost_gle_for_pos_sales_return.py b/erpnext/patches/v7_0/repost_gle_for_pos_sales_return.py index 3d7b43cebb..d3dd2e9aa6 100644 --- a/erpnext/patches/v7_0/repost_gle_for_pos_sales_return.py +++ b/erpnext/patches/v7_0/repost_gle_for_pos_sales_return.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import frappe -from frappe.utils import cint +from frappe.utils import cint, flt def execute(): frappe.reload_doctype("Sales Invoice") @@ -12,13 +12,13 @@ def execute(): filters={"docstatus": 1, "is_pos": 1, "is_return": 1}): si_doc = frappe.get_doc("Sales Invoice", si.name) if len(si_doc.payments) > 0: - delete_gle_for_voucher(si_doc.name) si_doc.set_paid_amount() si_doc.flags.ignore_validate_update_after_submit = True si_doc.save() - si_doc.run_method("make_gl_entries") + if si_doc.grand_total <= si_doc.paid_amount and si_doc.paid_amount < 0: + delete_gle_for_voucher(si_doc.name) + si_doc.run_method("make_gl_entries") def delete_gle_for_voucher(voucher_no): frappe.db.sql("""delete from `tabGL Entry` where voucher_no = %(voucher_no)s""", {'voucher_no': voucher_no}) - \ No newline at end of file