fix: fixed tests, separated a method for shipping charges
This commit is contained in:
parent
74ccaeb07d
commit
a8e2c02e14
@ -811,29 +811,12 @@ class TestPurchaseInvoice(unittest.TestCase):
|
|||||||
|
|
||||||
pi.shipping_rule = shipping_rule.name
|
pi.shipping_rule = shipping_rule.name
|
||||||
pi.insert()
|
pi.insert()
|
||||||
|
|
||||||
shipping_amount = 0.0
|
|
||||||
for condition in shipping_rule.get("conditions"):
|
|
||||||
if not condition.to_value or (flt(condition.from_value) <= pi.net_total <= flt(condition.to_value)):
|
|
||||||
shipping_amount = condition.shipping_amount
|
|
||||||
|
|
||||||
shipping_charge = {
|
|
||||||
"doctype": "Purchase Taxes and Charges",
|
|
||||||
"category": "Valuation and Total",
|
|
||||||
"charge_type": "Actual",
|
|
||||||
"account_head": shipping_rule.account,
|
|
||||||
"cost_center": shipping_rule.cost_center,
|
|
||||||
"tax_amount": shipping_amount,
|
|
||||||
"description": shipping_rule.name,
|
|
||||||
"add_deduct_tax": "Add"
|
|
||||||
}
|
|
||||||
pi.append("taxes", shipping_charge)
|
|
||||||
pi.save()
|
pi.save()
|
||||||
|
|
||||||
self.assertEqual(pi.net_total, 1250)
|
self.assertEqual(pi.net_total, 1250)
|
||||||
|
|
||||||
self.assertEqual(pi.total_taxes_and_charges, 462.3)
|
self.assertEqual(pi.total_taxes_and_charges, 354.1)
|
||||||
self.assertEqual(pi.grand_total, 1712.3)
|
self.assertEqual(pi.grand_total, 1604.1)
|
||||||
|
|
||||||
def test_make_pi_without_terms(self):
|
def test_make_pi_without_terms(self):
|
||||||
pi = make_purchase_invoice(do_not_save=1)
|
pi = make_purchase_invoice(do_not_save=1)
|
||||||
|
@ -1603,28 +1603,12 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
|
|
||||||
si.shipping_rule = shipping_rule.name
|
si.shipping_rule = shipping_rule.name
|
||||||
si.insert()
|
si.insert()
|
||||||
|
|
||||||
shipping_amount = 0.0
|
|
||||||
for condition in shipping_rule.get("conditions"):
|
|
||||||
if not condition.to_value or (flt(condition.from_value) <= si.net_total <= flt(condition.to_value)):
|
|
||||||
shipping_amount = condition.shipping_amount
|
|
||||||
|
|
||||||
shipping_charge = {
|
|
||||||
"doctype": "Sales Taxes and Charges",
|
|
||||||
"category": "Valuation and Total",
|
|
||||||
"charge_type": "Actual",
|
|
||||||
"account_head": shipping_rule.account,
|
|
||||||
"cost_center": shipping_rule.cost_center,
|
|
||||||
"tax_amount": shipping_amount,
|
|
||||||
"description": shipping_rule.name
|
|
||||||
}
|
|
||||||
si.append("taxes", shipping_charge)
|
|
||||||
si.save()
|
si.save()
|
||||||
|
|
||||||
self.assertEqual(si.net_total, 1250)
|
self.assertEqual(si.net_total, 1250)
|
||||||
|
|
||||||
self.assertEqual(si.total_taxes_and_charges, 577.05)
|
self.assertEqual(si.total_taxes_and_charges, 468.85)
|
||||||
self.assertEqual(si.grand_total, 1827.05)
|
self.assertEqual(si.grand_total, 1718.85)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ class calculate_taxes_and_totals(object):
|
|||||||
self.initialize_taxes()
|
self.initialize_taxes()
|
||||||
self.determine_exclusive_rate()
|
self.determine_exclusive_rate()
|
||||||
self.calculate_net_total()
|
self.calculate_net_total()
|
||||||
|
self.calculate_shipping_charges()
|
||||||
self.calculate_taxes()
|
self.calculate_taxes()
|
||||||
self.manipulate_grand_total_for_inclusive_tax()
|
self.manipulate_grand_total_for_inclusive_tax()
|
||||||
self.calculate_totals()
|
self.calculate_totals()
|
||||||
@ -258,6 +259,7 @@ class calculate_taxes_and_totals(object):
|
|||||||
|
|
||||||
self.doc.round_floats_in(self.doc, ["total", "base_total", "net_total", "base_net_total"])
|
self.doc.round_floats_in(self.doc, ["total", "base_total", "net_total", "base_net_total"])
|
||||||
|
|
||||||
|
def calculate_shipping_charges(self):
|
||||||
if hasattr(self.doc, "shipping_rule") and self.doc.shipping_rule:
|
if hasattr(self.doc, "shipping_rule") and self.doc.shipping_rule:
|
||||||
shipping_rule = frappe.get_doc("Shipping Rule", self.doc.shipping_rule)
|
shipping_rule = frappe.get_doc("Shipping Rule", self.doc.shipping_rule)
|
||||||
shipping_rule.apply(self.doc)
|
shipping_rule.apply(self.doc)
|
||||||
|
@ -81,6 +81,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
this.initialize_taxes();
|
this.initialize_taxes();
|
||||||
this.determine_exclusive_rate();
|
this.determine_exclusive_rate();
|
||||||
this.calculate_net_total();
|
this.calculate_net_total();
|
||||||
|
calculate_shipping_charges();
|
||||||
this.calculate_taxes();
|
this.calculate_taxes();
|
||||||
this.manipulate_grand_total_for_inclusive_tax();
|
this.manipulate_grand_total_for_inclusive_tax();
|
||||||
this.calculate_totals();
|
this.calculate_totals();
|
||||||
@ -267,6 +268,8 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
me.frm.doc.base_net_total += item.base_net_amount;
|
me.frm.doc.base_net_total += item.base_net_amount;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
calculate_shipping_charges() {
|
||||||
frappe.model.round_floats_in(this.frm.doc, ["total", "base_total", "net_total", "base_net_total"]);
|
frappe.model.round_floats_in(this.frm.doc, ["total", "base_total", "net_total", "base_net_total"]);
|
||||||
if(frappe.meta.get_docfield(this.frm.doc.doctype,"shipping_rule",this.frm.doc.name)) {
|
if(frappe.meta.get_docfield(this.frm.doc.doctype,"shipping_rule",this.frm.doc.name)) {
|
||||||
this.shipping_rule()
|
this.shipping_rule()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user