Skip to content

Commit

Permalink
Merge pull request #37319 from ruthra-kumar/test_fixtures_for_sales_p…
Browse files Browse the repository at this point in the history
…urchase_invoice

test: use fixtures for sales and purchase invoice
  • Loading branch information
ruthra-kumar authored Oct 15, 2023
2 parents afef9dc + fbabf4a commit dfd40ca
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import unittest

import frappe
from frappe.tests.utils import change_settings
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import add_days, cint, flt, getdate, nowdate, today

import erpnext
Expand Down Expand Up @@ -38,7 +38,7 @@
test_ignore = ["Serial No"]


class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
class TestPurchaseInvoice(FrappeTestCase, StockTestMixin):
@classmethod
def setUpClass(self):
unlink_payment_on_cancel_of_invoice()
Expand All @@ -48,6 +48,9 @@ def setUpClass(self):
def tearDownClass(self):
unlink_payment_on_cancel_of_invoice(0)

def tearDown(self):
frappe.db.rollback()

def test_purchase_invoice_received_qty(self):
"""
1. Test if received qty is validated against accepted + rejected
Expand Down Expand Up @@ -422,6 +425,7 @@ def test_purchase_invoice_calculation(self):
self.assertEqual(tax.tax_amount, expected_values[i][1])
self.assertEqual(tax.total, expected_values[i][2])

@change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
def test_purchase_invoice_with_advance(self):
from erpnext.accounts.doctype.journal_entry.test_journal_entry import (
test_records as jv_test_records,
Expand Down Expand Up @@ -476,6 +480,7 @@ def test_purchase_invoice_with_advance(self):
)
)

@change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
def test_invoice_with_advance_and_multi_payment_terms(self):
from erpnext.accounts.doctype.journal_entry.test_journal_entry import (
test_records as jv_test_records,
Expand Down Expand Up @@ -1220,6 +1225,7 @@ def test_deferred_expense_via_journal_entry(self):
acc_settings.submit_journal_entriessubmit_journal_entries = 0
acc_settings.save()

@change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
def test_gain_loss_with_advance_entry(self):
unlink_enabled = frappe.db.get_value(
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice"
Expand Down Expand Up @@ -1420,6 +1426,7 @@ def test_gain_loss_with_advance_entry(self):
)
frappe.db.set_value("Company", "_Test Company", "exchange_gain_loss_account", original_account)

@change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
def test_purchase_invoice_advance_taxes(self):
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry

Expand Down
40 changes: 23 additions & 17 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import frappe
from frappe.model.dynamic_links import get_dynamic_link_map
from frappe.tests.utils import change_settings
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import add_days, flt, getdate, nowdate, today

import erpnext
Expand Down Expand Up @@ -45,13 +45,17 @@
from erpnext.stock.utils import get_incoming_rate, get_stock_balance


class TestSalesInvoice(unittest.TestCase):
class TestSalesInvoice(FrappeTestCase):
def setUp(self):
from erpnext.stock.doctype.stock_ledger_entry.test_stock_ledger_entry import create_items

create_items(["_Test Internal Transfer Item"], uoms=[{"uom": "Box", "conversion_factor": 10}])
create_internal_parties()
setup_accounts()
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)

def tearDown(self):
frappe.db.rollback()

def make(self):
w = frappe.copy_doc(test_records[0])
Expand Down Expand Up @@ -179,6 +183,7 @@ def test_payment_entry_unlink_against_invoice(self):
self.assertRaises(frappe.LinkExistsError, si.cancel)
unlink_payment_on_cancel_of_invoice()

@change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
def test_payment_entry_unlink_against_standalone_credit_note(self):
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry

Expand Down Expand Up @@ -1300,6 +1305,7 @@ def _insert_delivery_note(self):
dn.submit()
return dn

@change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
def test_sales_invoice_with_advance(self):
from erpnext.accounts.doctype.journal_entry.test_journal_entry import (
test_records as jv_test_records,
Expand Down Expand Up @@ -2775,6 +2781,13 @@ def test_additional_discount_for_sales_invoice_with_discount_accounting_enabled(
company="_Test Company",
)

tds_payable_account = create_account(
account_name="TDS Payable",
account_type="Tax",
parent_account="Duties and Taxes - _TC",
company="_Test Company",
)

si = create_sales_invoice(parent_cost_center="Main - _TC", do_not_save=1)
si.apply_discount_on = "Grand Total"
si.additional_discount_account = additional_discount_account
Expand Down Expand Up @@ -3073,8 +3086,8 @@ def test_sales_commission(self):
si.commission_rate = commission_rate
self.assertRaises(frappe.ValidationError, si.save)

@change_settings("Accounts Settings", {"acc_frozen_upto": add_days(getdate(), 1)})
def test_sales_invoice_submission_post_account_freezing_date(self):
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", add_days(getdate(), 1))
si = create_sales_invoice(do_not_save=True)
si.posting_date = add_days(getdate(), 1)
si.save()
Expand All @@ -3083,8 +3096,6 @@ def test_sales_invoice_submission_post_account_freezing_date(self):
si.posting_date = getdate()
si.submit()

frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)

def test_over_billing_case_against_delivery_note(self):
"""
Test a case where duplicating the item with qty = 1 in the invoice
Expand Down Expand Up @@ -3113,18 +3124,20 @@ def test_over_billing_case_against_delivery_note(self):

frappe.db.set_single_value("Accounts Settings", "over_billing_allowance", over_billing_allowance)

@change_settings(
"Accounts Settings",
{
"book_deferred_entries_via_journal_entry": 1,
"submit_journal_entries": 1,
},
)
def test_multi_currency_deferred_revenue_via_journal_entry(self):
deferred_account = create_account(
account_name="Deferred Revenue",
parent_account="Current Liabilities - _TC",
company="_Test Company",
)

acc_settings = frappe.get_single("Accounts Settings")
acc_settings.book_deferred_entries_via_journal_entry = 1
acc_settings.submit_journal_entries = 1
acc_settings.save()

item = create_item("_Test Item for Deferred Accounting")
item.enable_deferred_expense = 1
item.item_defaults[0].deferred_revenue_account = deferred_account
Expand Down Expand Up @@ -3190,13 +3203,6 @@ def test_multi_currency_deferred_revenue_via_journal_entry(self):
self.assertEqual(expected_gle[i][2], gle.debit)
self.assertEqual(getdate(expected_gle[i][3]), gle.posting_date)

acc_settings = frappe.get_single("Accounts Settings")
acc_settings.book_deferred_entries_via_journal_entry = 0
acc_settings.submit_journal_entries = 0
acc_settings.save()

frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)

def test_standalone_serial_no_return(self):
si = create_sales_invoice(
item_code="_Test Serialized Item With Series", update_stock=True, is_return=True, qty=-1
Expand Down
7 changes: 6 additions & 1 deletion erpnext/accounts/doctype/subscription/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils.data import (
add_days,
add_months,
Expand All @@ -21,11 +22,15 @@
test_dependencies = ("UOM", "Item Group", "Item")


class TestSubscription(unittest.TestCase):
class TestSubscription(FrappeTestCase):
def setUp(self):
make_plans()
create_parties()
reset_settings()
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)

def tearDown(self):
frappe.db.rollback()

def test_create_subscription_with_trial_with_correct_period(self):
subscription = create_subscription(
Expand Down

0 comments on commit dfd40ca

Please sign in to comment.