test: test for auto write-off amount

This commit is contained in:
Deepesh Garg
2022-03-25 18:02:14 +05:30
parent 665bd4c510
commit 6a50f36b31
3 changed files with 37 additions and 5 deletions

View File

@@ -812,12 +812,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': 'Cash', 'account': 'Cash - TCP1', 'amount': 60})
pos.change_amount = 5.0
pos.write_off_outstanding_amount_automatically = 1
pos.insert()
pos.submit()
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):
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))
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_write_off_amount()

View File

@@ -667,6 +667,10 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
}));
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_write_off_amount();
},
@@ -815,12 +819,12 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
calculate_write_off_amount: function() {
if (this.frm.doc.write_off_outstanding_amount_automatically) {
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.write_off_amount = flt(this.frm.doc.outstanding_amount, precision("write_off_amount"));
this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate,
precision("base_write_off_amount"));
this.calculate_outstanding_amount(false);
}
this.calculate_outstanding_amount(false);
}
});