Skip to content

Commit

Permalink
Merge pull request #32806 from frappe/mergify/bp/version-13-hotfix/pr…
Browse files Browse the repository at this point in the history
…-32779

fix: Mode of payment for returns in POS Sales Invoice (backport #32779)
  • Loading branch information
deepeshgarg007 authored Nov 1, 2022
2 parents 2f6d55d + 12b1534 commit a914838
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
3 changes: 2 additions & 1 deletion erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,8 @@ def test_pos_returns_with_repayment(self):
pos_return.insert()
pos_return.submit()

self.assertEqual(pos_return.get("payments")[0].amount, -1000)
self.assertEqual(pos_return.get("payments")[0].amount, -500)
self.assertEqual(pos_return.get("payments")[1].amount, -500)

def test_pos_change_amount(self):
make_pos_profile(
Expand Down
39 changes: 24 additions & 15 deletions erpnext/controllers/taxes_and_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,24 +890,33 @@ def set_item_wise_tax_breakup(self):
self.doc.other_charges_calculation = get_itemised_tax_breakup_html(self.doc)

def set_total_amount_to_default_mop(self, total_amount_to_pay):
default_mode_of_payment = frappe.db.get_value(
"POS Payment Method",
{"parent": self.doc.pos_profile, "default": 1},
["mode_of_payment"],
as_dict=1,
)
total_paid_amount = 0
for payment in self.doc.get("payments"):
total_paid_amount += (
payment.amount if self.doc.party_account_currency == self.doc.currency else payment.base_amount
)

pending_amount = total_amount_to_pay - total_paid_amount

if default_mode_of_payment:
self.doc.payments = []
self.doc.append(
"payments",
{
"mode_of_payment": default_mode_of_payment.mode_of_payment,
"amount": total_amount_to_pay,
"default": 1,
},
if pending_amount > 0:
default_mode_of_payment = frappe.db.get_value(
"POS Payment Method",
{"parent": self.doc.pos_profile, "default": 1},
["mode_of_payment"],
as_dict=1,
)

if default_mode_of_payment:
self.doc.payments = []
self.doc.append(
"payments",
{
"mode_of_payment": default_mode_of_payment.mode_of_payment,
"amount": pending_amount,
"default": 1,
},
)


def get_itemised_tax_breakup_html(doc):
if not doc.taxes:
Expand Down

0 comments on commit a914838

Please sign in to comment.