test: test for auto write-off amount

(cherry picked from commit 6a50f36b3167d43b1e964d4f0cf96af587f1a4a2)

# Conflicts:
#	erpnext/public/js/controllers/taxes_and_totals.js
This commit is contained in:
Deepesh Garg 2022-03-25 18:02:14 +05:30 committed by mergify-bot
parent b2ac773cca
commit 19b1b1f4ba
3 changed files with 40 additions and 3 deletions

View File

@ -813,12 +813,37 @@ class TestSalesInvoice(unittest.TestCase):
pos.append("payments", {'mode_of_payment': 'Bank Draft', 'account': '_Test Bank - TCP1', 'amount': 50}) pos.append("payments", {'mode_of_payment': 'Bank Draft', 'account': '_Test Bank - TCP1', 'amount': 50})
pos.append("payments", {'mode_of_payment': 'Cash', 'account': 'Cash - TCP1', 'amount': 60}) pos.append("payments", {'mode_of_payment': 'Cash', 'account': 'Cash - TCP1', 'amount': 60})
pos.change_amount = 5.0 pos.write_off_outstanding_amount_automatically = 1
pos.insert() pos.insert()
pos.submit() pos.submit()
self.assertEqual(pos.grand_total, 100.0) self.assertEqual(pos.grand_total, 100.0)
self.assertEqual(pos.write_off_amount, -5) self.assertEqual(pos.write_off_amount, 0)
def test_auto_write_off_amount(self):
make_pos_profile(company="_Test Company with perpetual inventory", income_account = "Sales - TCP1",
expense_account = "Cost of Goods Sold - TCP1", warehouse="Stores - TCP1", cost_center = "Main - TCP1", write_off_account="_Test Write Off - TCP1")
make_purchase_receipt(company= "_Test Company with perpetual inventory",
item_code= "_Test FG Item",warehouse= "Stores - TCP1", cost_center= "Main - TCP1")
pos = create_sales_invoice(company= "_Test Company with perpetual inventory",
debit_to="Debtors - TCP1", item_code= "_Test FG Item", warehouse="Stores - TCP1",
income_account = "Sales - TCP1", expense_account = "Cost of Goods Sold - TCP1",
cost_center = "Main - TCP1", do_not_save=True)
pos.is_pos = 1
pos.update_stock = 1
pos.append("payments", {'mode_of_payment': 'Bank Draft', 'account': '_Test Bank - TCP1', 'amount': 50})
pos.append("payments", {'mode_of_payment': 'Cash', 'account': 'Cash - TCP1', 'amount': 40})
pos.write_off_outstanding_amount_automatically = 1
pos.insert()
pos.submit()
self.assertEqual(pos.grand_total, 100.0)
self.assertEqual(pos.write_off_amount, 10)
def test_pos_with_no_gl_entry_for_change_amount(self): def test_pos_with_no_gl_entry_for_change_amount(self):
frappe.db.set_value('Accounts Settings', None, 'post_change_gl_entries', 0) frappe.db.set_value('Accounts Settings', None, 'post_change_gl_entries', 0)

View File

@ -580,6 +580,9 @@ class calculate_taxes_and_totals(object):
.format(self.doc.party_account_currency, invoice_total)) .format(self.doc.party_account_currency, invoice_total))
if self.doc.docstatus == 0: if self.doc.docstatus == 0:
if self.doc.get('write_off_outstanding_amount_automatically'):
self.doc.write_off_amount = 0
self.calculate_outstanding_amount() self.calculate_outstanding_amount()
self.calculate_write_off_amount() self.calculate_write_off_amount()

View File

@ -689,6 +689,10 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
})); }));
this.frm.doc.total_advance = flt(total_allocated_amount, precision("total_advance")); this.frm.doc.total_advance = flt(total_allocated_amount, precision("total_advance"));
if (this.frm.doc.write_off_outstanding_amount_automatically) {
this.frm.doc.write_off_amount = 0;
}
this.calculate_outstanding_amount(update_paid_amount); this.calculate_outstanding_amount(update_paid_amount);
<<<<<<< HEAD <<<<<<< HEAD
} }
@ -849,13 +853,18 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
======= =======
calculate_write_off_amount: function() { calculate_write_off_amount: function() {
if (this.frm.doc.write_off_outstanding_amount_automatically) { if (this.frm.doc.write_off_outstanding_amount_automatically) {
<<<<<<< HEAD
>>>>>>> 2e33e748ea (fix: Client side changes for POS Write off amount) >>>>>>> 2e33e748ea (fix: Client side changes for POS Write off amount)
this.frm.doc.write_off_amount = flt(this.frm.doc.grand_total - this.frm.doc.paid_amount this.frm.doc.write_off_amount = flt(this.frm.doc.grand_total - this.frm.doc.paid_amount
+ this.frm.doc.change_amount, precision("write_off_amount")); + this.frm.doc.change_amount, precision("write_off_amount"));
=======
this.frm.doc.write_off_amount = flt(this.frm.doc.outstanding_amount, precision("write_off_amount"));
>>>>>>> 6a50f36b31 (test: test for auto write-off amount)
this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate, this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate,
precision("base_write_off_amount")); precision("base_write_off_amount"));
}
this.calculate_outstanding_amount(false); this.calculate_outstanding_amount(false);
} }
}
}; };