[fix] POS paid amount validation using grand total
This commit is contained in:
parent
08b39b1ff8
commit
15f7b1ee1a
@ -375,7 +375,7 @@ class SalesInvoice(SellingController):
|
||||
frappe.throw(_("Cash or Bank Account is mandatory for making payment entry"))
|
||||
|
||||
if flt(self.paid_amount) + flt(self.write_off_amount) \
|
||||
- flt(self.base_grand_total) > 1/(10**(self.precision("base_grand_total") + 1)):
|
||||
- flt(self.grand_total) > 1/(10**(self.precision("grand_total") + 1)):
|
||||
frappe.throw(_("""Paid amount + Write Off Amount can not be greater than Grand Total"""))
|
||||
|
||||
|
||||
@ -471,7 +471,7 @@ class SalesInvoice(SellingController):
|
||||
frappe.db.set(self,'paid_amount',0)
|
||||
|
||||
frappe.db.set(self, 'base_paid_amount',
|
||||
flt(self.paid_amount*self.conversion_rate, self.precision("base_paid_amount")))
|
||||
flt(self.paid_amount*self.conversion_rate, self.precision("base_paid_amount")))
|
||||
|
||||
def check_prev_docstatus(self):
|
||||
for d in self.get('items'):
|
||||
|
@ -283,8 +283,8 @@ class calculate_taxes_and_totals(object):
|
||||
last_tax.tax_amount += diff
|
||||
last_tax.tax_amount_after_discount_amount += diff
|
||||
last_tax.total += diff
|
||||
|
||||
self._set_in_company_currency(last_tax,
|
||||
|
||||
self._set_in_company_currency(last_tax,
|
||||
["total", "tax_amount", "tax_amount_after_discount_amount"])
|
||||
|
||||
def calculate_totals(self):
|
||||
@ -319,22 +319,22 @@ class calculate_taxes_and_totals(object):
|
||||
self.doc.round_floats_in(self.doc, ["grand_total", "base_grand_total"])
|
||||
|
||||
if self.doc.meta.get_field("rounded_total"):
|
||||
self.doc.rounded_total = round_based_on_smallest_currency_fraction(self.doc.grand_total,
|
||||
self.doc.rounded_total = round_based_on_smallest_currency_fraction(self.doc.grand_total,
|
||||
self.doc.currency, self.doc.precision("rounded_total"))
|
||||
if self.doc.meta.get_field("base_rounded_total"):
|
||||
company_currency = get_company_currency(self.doc.company)
|
||||
|
||||
|
||||
self.doc.base_rounded_total = \
|
||||
round_based_on_smallest_currency_fraction(self.doc.base_grand_total,
|
||||
round_based_on_smallest_currency_fraction(self.doc.base_grand_total,
|
||||
company_currency, self.doc.precision("base_rounded_total"))
|
||||
|
||||
def _cleanup(self):
|
||||
for tax in self.doc.get("taxes"):
|
||||
tax.item_wise_tax_detail = json.dumps(tax.item_wise_tax_detail, separators=(',', ':'))
|
||||
|
||||
|
||||
def set_discount_amount(self):
|
||||
if not self.doc.discount_amount and self.doc.additional_discount_percentage:
|
||||
self.doc.discount_amount = flt(flt(self.doc.get(scrub(self.doc.apply_discount_on)))
|
||||
self.doc.discount_amount = flt(flt(self.doc.get(scrub(self.doc.apply_discount_on)))
|
||||
* self.doc.additional_discount_percentage / 100, self.doc.precision("discount_amount"))
|
||||
|
||||
def apply_discount_amount(self):
|
||||
@ -397,13 +397,13 @@ class calculate_taxes_and_totals(object):
|
||||
for adv in self.doc.get("advances")])
|
||||
|
||||
self.doc.total_advance = flt(total_allocated_amount, self.doc.precision("total_advance"))
|
||||
|
||||
|
||||
if self.doc.party_account_currency == self.doc.currency:
|
||||
invoice_total = self.doc.grand_total
|
||||
else:
|
||||
invoice_total = flt(self.doc.grand_total * self.doc.conversion_rate,
|
||||
invoice_total = flt(self.doc.grand_total * self.doc.conversion_rate,
|
||||
self.doc.precision("grand_total"))
|
||||
|
||||
|
||||
if invoice_total > 0 and self.doc.total_advance > invoice_total:
|
||||
frappe.throw(_("Advance amount cannot be greater than {0} {1}")
|
||||
.format(self.doc.party_account_currency, invoice_total))
|
||||
@ -417,21 +417,23 @@ class calculate_taxes_and_totals(object):
|
||||
# total_advance is only for non POS Invoice
|
||||
if self.doc.is_return:
|
||||
return
|
||||
|
||||
|
||||
self.doc.round_floats_in(self.doc, ["grand_total", "total_advance", "write_off_amount"])
|
||||
self._set_in_company_currency(self.doc, ['write_off_amount'])
|
||||
|
||||
if self.doc.party_account_currency == self.doc.currency:
|
||||
total_amount_to_pay = flt(self.doc.grand_total - self.doc.total_advance
|
||||
total_amount_to_pay = flt(self.doc.grand_total - self.doc.total_advance
|
||||
- flt(self.doc.write_off_amount), self.doc.precision("grand_total"))
|
||||
else:
|
||||
total_amount_to_pay = flt(flt(self.doc.grand_total *
|
||||
self.doc.conversion_rate, self.doc.precision("grand_total")) - self.doc.total_advance
|
||||
self.doc.conversion_rate, self.doc.precision("grand_total")) - self.doc.total_advance
|
||||
- flt(self.doc.base_write_off_amount), self.doc.precision("grand_total"))
|
||||
|
||||
|
||||
if self.doc.doctype == "Sales Invoice":
|
||||
self.doc.round_floats_in(self.doc, ["paid_amount"])
|
||||
paid_amount = self.doc.paid_amount \
|
||||
if self.doc.party_account_currency == self.doc.currency else self.doc.base_paid_amount
|
||||
self.doc.outstanding_amount = flt(total_amount_to_pay - flt(paid_amount),
|
||||
self.doc.outstanding_amount = flt(total_amount_to_pay - flt(paid_amount),
|
||||
self.doc.precision("outstanding_amount"))
|
||||
elif self.doc.doctype == "Purchase Invoice":
|
||||
self.doc.outstanding_amount = flt(total_amount_to_pay, self.doc.precision("outstanding_amount"))
|
||||
self.doc.outstanding_amount = flt(total_amount_to_pay, self.doc.precision("outstanding_amount"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user