mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-13 10:11:20 +00:00
refactor(test): make purchase invoice tests deterministic
This commit is contained in:
@@ -40,18 +40,11 @@ from erpnext.tests.utils import ERPNextTestSuite
|
|||||||
|
|
||||||
|
|
||||||
class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin):
|
class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin):
|
||||||
@classmethod
|
def setUp(self):
|
||||||
def setUpClass(cls):
|
|
||||||
super().setUpClass()
|
|
||||||
unlink_payment_on_cancel_of_invoice()
|
unlink_payment_on_cancel_of_invoice()
|
||||||
frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1)
|
frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1)
|
||||||
|
self.load_test_records("Purchase Invoice")
|
||||||
@classmethod
|
self.load_test_records("Journal Entry")
|
||||||
def tearDownClass(cls):
|
|
||||||
unlink_payment_on_cancel_of_invoice(0)
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
frappe.db.rollback()
|
|
||||||
|
|
||||||
def test_purchase_invoice_qty(self):
|
def test_purchase_invoice_qty(self):
|
||||||
pi = make_purchase_invoice(qty=0, do_not_save=True)
|
pi = make_purchase_invoice(qty=0, do_not_save=True)
|
||||||
@@ -349,6 +342,9 @@ class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin):
|
|||||||
self.assertEqual(expected_values[gle.account][1], gle.debit)
|
self.assertEqual(expected_values[gle.account][1], gle.debit)
|
||||||
self.assertEqual(expected_values[gle.account][2], gle.credit)
|
self.assertEqual(expected_values[gle.account][2], gle.credit)
|
||||||
|
|
||||||
|
@ERPNextTestSuite.change_settings(
|
||||||
|
"Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1}
|
||||||
|
)
|
||||||
def test_purchase_invoice_with_exchange_rate_difference(self):
|
def test_purchase_invoice_with_exchange_rate_difference(self):
|
||||||
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
|
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
|
||||||
make_purchase_invoice as create_purchase_invoice,
|
make_purchase_invoice as create_purchase_invoice,
|
||||||
@@ -372,7 +368,7 @@ class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin):
|
|||||||
|
|
||||||
# fetching the latest GL Entry with exchange gain and loss account account
|
# fetching the latest GL Entry with exchange gain and loss account account
|
||||||
amount = frappe.db.get_value(
|
amount = frappe.db.get_value(
|
||||||
"GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pi.name}, "debit"
|
"GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pi.name}, "credit"
|
||||||
)
|
)
|
||||||
discrepancy_caused_by_exchange_rate_diff = abs(
|
discrepancy_caused_by_exchange_rate_diff = abs(
|
||||||
pi.items[0].base_net_amount - pr.items[0].base_net_amount
|
pi.items[0].base_net_amount - pr.items[0].base_net_amount
|
||||||
@@ -418,14 +414,14 @@ class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin):
|
|||||||
|
|
||||||
# fetching the latest GL Entry with exchange gain and loss account account
|
# fetching the latest GL Entry with exchange gain and loss account account
|
||||||
amount = frappe.db.get_value(
|
amount = frappe.db.get_value(
|
||||||
"GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pi.name}, "debit"
|
"GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pi.name}, "credit"
|
||||||
)
|
)
|
||||||
|
|
||||||
discrepancy_caused_by_exchange_rate_diff = abs(
|
discrepancy_caused_by_exchange_rate_diff = abs(
|
||||||
pi.items[1].base_net_amount - pr.items[1].base_net_amount
|
pi.items[1].base_net_amount - pr.items[1].base_net_amount
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(discrepancy_caused_by_exchange_rate_diff, amount)
|
self.assertEqual(flt(discrepancy_caused_by_exchange_rate_diff, 2), amount)
|
||||||
|
|
||||||
def test_purchase_invoice_change_naming_series(self):
|
def test_purchase_invoice_change_naming_series(self):
|
||||||
pi = frappe.copy_doc(self.globalTestRecords["Purchase Invoice"][1])
|
pi = frappe.copy_doc(self.globalTestRecords["Purchase Invoice"][1])
|
||||||
@@ -2276,6 +2272,7 @@ class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin):
|
|||||||
|
|
||||||
def test_create_purchase_invoice_without_mandatory(self):
|
def test_create_purchase_invoice_without_mandatory(self):
|
||||||
pi = frappe.new_doc("Purchase Invoice")
|
pi = frappe.new_doc("Purchase Invoice")
|
||||||
|
pi.company = self.companies[0].name
|
||||||
pi.flags.ignore_mandatory = True
|
pi.flags.ignore_mandatory = True
|
||||||
pi.insert(ignore_permissions=True)
|
pi.insert(ignore_permissions=True)
|
||||||
|
|
||||||
@@ -2404,6 +2401,7 @@ class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin):
|
|||||||
"doctype": "Serial No",
|
"doctype": "Serial No",
|
||||||
"item_code": serial_item,
|
"item_code": serial_item,
|
||||||
"serial_no": serial_no,
|
"serial_no": serial_no,
|
||||||
|
"company": self.companies[0].name,
|
||||||
}
|
}
|
||||||
).insert()
|
).insert()
|
||||||
|
|
||||||
|
|||||||
209
erpnext/accounts/doctype/purchase_invoice/test_records.json
Normal file
209
erpnext/accounts/doctype/purchase_invoice/test_records.json
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"bill_no": "NA",
|
||||||
|
"buying_price_list": "_Test Price List",
|
||||||
|
"company": "_Test Company",
|
||||||
|
"conversion_rate": 1,
|
||||||
|
"credit_to": "_Test Payable - _TC",
|
||||||
|
"currency": "INR",
|
||||||
|
"doctype": "Purchase Invoice",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"amount": 500,
|
||||||
|
"base_amount": 500,
|
||||||
|
"base_rate": 50,
|
||||||
|
"conversion_factor": 1.0,
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"doctype": "Purchase Invoice Item",
|
||||||
|
"expense_account": "_Test Account Cost for Goods Sold - _TC",
|
||||||
|
"item_code": "_Test Item Home Desktop 100",
|
||||||
|
"item_name": "_Test Item Home Desktop 100",
|
||||||
|
"item_tax_template": "_Test Account Excise Duty @ 10 - _TC",
|
||||||
|
"parentfield": "items",
|
||||||
|
"qty": 10,
|
||||||
|
"rate": 50,
|
||||||
|
"uom": "_Test UOM",
|
||||||
|
"warehouse": "_Test Warehouse - _TC"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"amount": 750,
|
||||||
|
"base_amount": 750,
|
||||||
|
"base_rate": 150,
|
||||||
|
"conversion_factor": 1.0,
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"doctype": "Purchase Invoice Item",
|
||||||
|
"expense_account": "_Test Account Cost for Goods Sold - _TC",
|
||||||
|
"item_code": "_Test Item Home Desktop 200",
|
||||||
|
"item_name": "_Test Item Home Desktop 200",
|
||||||
|
"parentfield": "items",
|
||||||
|
"qty": 5,
|
||||||
|
"rate": 150,
|
||||||
|
"uom": "_Test UOM",
|
||||||
|
"warehouse": "_Test Warehouse - _TC"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"grand_total": 0,
|
||||||
|
"naming_series": "T-PINV-",
|
||||||
|
"taxes": [
|
||||||
|
{
|
||||||
|
"account_head": "_Test Account Shipping Charges - _TC",
|
||||||
|
"add_deduct_tax": "Add",
|
||||||
|
"category": "Valuation and Total",
|
||||||
|
"charge_type": "Actual",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"description": "Shipping Charges",
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"parentfield": "taxes",
|
||||||
|
"tax_amount": 100
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account_head": "_Test Account Customs Duty - _TC",
|
||||||
|
"add_deduct_tax": "Add",
|
||||||
|
"category": "Valuation",
|
||||||
|
"charge_type": "On Net Total",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"description": "Customs Duty",
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"parentfield": "taxes",
|
||||||
|
"rate": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account_head": "_Test Account Excise Duty - _TC",
|
||||||
|
"add_deduct_tax": "Add",
|
||||||
|
"category": "Total",
|
||||||
|
"charge_type": "On Net Total",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"description": "Excise Duty",
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"parentfield": "taxes",
|
||||||
|
"rate": 12
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account_head": "_Test Account Education Cess - _TC",
|
||||||
|
"add_deduct_tax": "Add",
|
||||||
|
"category": "Total",
|
||||||
|
"charge_type": "On Previous Row Amount",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"description": "Education Cess",
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"parentfield": "taxes",
|
||||||
|
"rate": 2,
|
||||||
|
"row_id": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account_head": "_Test Account S&H Education Cess - _TC",
|
||||||
|
"add_deduct_tax": "Add",
|
||||||
|
"category": "Total",
|
||||||
|
"charge_type": "On Previous Row Amount",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"description": "S&H Education Cess",
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"parentfield": "taxes",
|
||||||
|
"rate": 1,
|
||||||
|
"row_id": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account_head": "_Test Account CST - _TC",
|
||||||
|
"add_deduct_tax": "Add",
|
||||||
|
"category": "Total",
|
||||||
|
"charge_type": "On Previous Row Total",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"description": "CST",
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"parentfield": "taxes",
|
||||||
|
"rate": 2,
|
||||||
|
"row_id": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account_head": "_Test Account VAT - _TC",
|
||||||
|
"add_deduct_tax": "Add",
|
||||||
|
"category": "Total",
|
||||||
|
"charge_type": "On Net Total",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"description": "VAT",
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"parentfield": "taxes",
|
||||||
|
"rate": 12.5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account_head": "_Test Account Discount - _TC",
|
||||||
|
"add_deduct_tax": "Deduct",
|
||||||
|
"category": "Total",
|
||||||
|
"charge_type": "On Previous Row Total",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"description": "Discount",
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"parentfield": "taxes",
|
||||||
|
"rate": 10,
|
||||||
|
"row_id": 7
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"supplier": "_Test Supplier",
|
||||||
|
"supplier_name": "_Test Supplier"
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
"bill_no": "NA",
|
||||||
|
"buying_price_list": "_Test Price List",
|
||||||
|
"company": "_Test Company",
|
||||||
|
"conversion_rate": 1.0,
|
||||||
|
"credit_to": "_Test Payable - _TC",
|
||||||
|
"currency": "INR",
|
||||||
|
"doctype": "Purchase Invoice",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"conversion_factor": 1.0,
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"doctype": "Purchase Invoice Item",
|
||||||
|
"expense_account": "_Test Account Cost for Goods Sold - _TC",
|
||||||
|
"item_code": "_Test Item",
|
||||||
|
"item_name": "_Test Item",
|
||||||
|
"parentfield": "items",
|
||||||
|
"qty": 10.0,
|
||||||
|
"rate": 50.0,
|
||||||
|
"uom": "_Test UOM"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"grand_total": 0,
|
||||||
|
"naming_series": "T-PINV-",
|
||||||
|
"taxes": [
|
||||||
|
{
|
||||||
|
"account_head": "_Test Account Shipping Charges - _TC",
|
||||||
|
"add_deduct_tax": "Add",
|
||||||
|
"category": "Valuation and Total",
|
||||||
|
"charge_type": "Actual",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"description": "Shipping Charges",
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"parentfield": "taxes",
|
||||||
|
"tax_amount": 100.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account_head": "_Test Account VAT - _TC",
|
||||||
|
"add_deduct_tax": "Add",
|
||||||
|
"category": "Total",
|
||||||
|
"charge_type": "Actual",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"description": "VAT",
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"parentfield": "taxes",
|
||||||
|
"tax_amount": 120.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account_head": "_Test Account Customs Duty - _TC",
|
||||||
|
"add_deduct_tax": "Add",
|
||||||
|
"category": "Valuation",
|
||||||
|
"charge_type": "Actual",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"description": "Customs Duty",
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"parentfield": "taxes",
|
||||||
|
"tax_amount": 150.0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"supplier": "_Test Supplier",
|
||||||
|
"supplier_name": "_Test Supplier"
|
||||||
|
}
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user