test: tax merging from 2 Delivery Note to Sales Invoice
(cherry picked from commit 39a48a2e2a)
# Conflicts:
# erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
This commit is contained in:
@@ -3439,12 +3439,230 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
si.save()
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
def get_sales_invoice_for_e_invoice():
|
||||
si = make_sales_invoice_for_ewaybill()
|
||||
si.naming_series = "INV-2020-.#####"
|
||||
si.items = []
|
||||
si.append(
|
||||
"items",
|
||||
=======
|
||||
company = "_Test Company"
|
||||
customer = "_Test Customer"
|
||||
debtors_acc = "Debtors - _TC"
|
||||
advance_account = create_account(
|
||||
parent_account="Current Liabilities - _TC",
|
||||
account_name="Advances Received",
|
||||
company="_Test Company",
|
||||
account_type="Receivable",
|
||||
)
|
||||
|
||||
set_advance_flag(company="_Test Company", flag=1, default_account=advance_account)
|
||||
|
||||
pe = create_payment_entry(
|
||||
company=company,
|
||||
payment_type="Receive",
|
||||
party_type="Customer",
|
||||
party=customer,
|
||||
paid_from=advance_account,
|
||||
paid_to="Cash - _TC",
|
||||
paid_amount=1000,
|
||||
)
|
||||
pe.submit()
|
||||
|
||||
si = create_sales_invoice(
|
||||
company=company,
|
||||
customer=customer,
|
||||
do_not_save=True,
|
||||
do_not_submit=True,
|
||||
rate=1000,
|
||||
price_list_rate=1000,
|
||||
)
|
||||
si.base_grand_total = 1000
|
||||
si.grand_total = 1000
|
||||
si.set_advances()
|
||||
for advance in si.advances:
|
||||
advance.allocated_amount = 200 if advance.reference_name == pe.name else 0
|
||||
si.save()
|
||||
si.submit()
|
||||
|
||||
self.assertEqual(si.advances[0].allocated_amount, 200)
|
||||
|
||||
# Check GL Entry against partial from advance
|
||||
expected_gle = [
|
||||
[advance_account, 0.0, 1000.0, nowdate()],
|
||||
[advance_account, 200.0, 0.0, nowdate()],
|
||||
["Cash - _TC", 1000.0, 0.0, nowdate()],
|
||||
[debtors_acc, 0.0, 200.0, nowdate()],
|
||||
]
|
||||
check_gl_entries(self, pe.name, expected_gle, nowdate(), voucher_type="Payment Entry")
|
||||
si.reload()
|
||||
self.assertEqual(si.outstanding_amount, 800.0)
|
||||
|
||||
pr = frappe.get_doc("Payment Reconciliation")
|
||||
pr.company = company
|
||||
pr.party_type = "Customer"
|
||||
pr.party = customer
|
||||
pr.receivable_payable_account = debtors_acc
|
||||
pr.default_advance_account = advance_account
|
||||
pr.get_unreconciled_entries()
|
||||
|
||||
# allocate some more of the same advance
|
||||
# self.assertEqual(len(pr.invoices), 1)
|
||||
# self.assertEqual(len(pr.payments), 1)
|
||||
invoices = [x.as_dict() for x in pr.invoices if x.get("invoice_number") == si.name]
|
||||
payments = [x.as_dict() for x in pr.payments if x.get("reference_name") == pe.name]
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
pr.allocation[0].allocated_amount = 300
|
||||
pr.reconcile()
|
||||
|
||||
si.reload()
|
||||
self.assertEqual(si.outstanding_amount, 500.0)
|
||||
|
||||
# Check GL Entry against multi partial allocations from advance
|
||||
expected_gle = [
|
||||
[advance_account, 0.0, 1000.0, nowdate()],
|
||||
[advance_account, 200.0, 0.0, nowdate()],
|
||||
[advance_account, 300.0, 0.0, nowdate()],
|
||||
["Cash - _TC", 1000.0, 0.0, nowdate()],
|
||||
[debtors_acc, 0.0, 200.0, nowdate()],
|
||||
[debtors_acc, 0.0, 300.0, nowdate()],
|
||||
]
|
||||
check_gl_entries(self, pe.name, expected_gle, nowdate(), voucher_type="Payment Entry")
|
||||
set_advance_flag(company="_Test Company", flag=0, default_account="")
|
||||
|
||||
def test_pulling_advance_based_on_debit_to(self):
|
||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry
|
||||
|
||||
debtors2 = create_account(
|
||||
parent_account="Accounts Receivable - _TC",
|
||||
account_name="Debtors 2",
|
||||
company="_Test Company",
|
||||
account_type="Receivable",
|
||||
)
|
||||
si = create_sales_invoice(do_not_submit=True)
|
||||
si.debit_to = debtors2
|
||||
si.save()
|
||||
|
||||
pe = create_payment_entry(
|
||||
company=si.company,
|
||||
payment_type="Receive",
|
||||
party_type="Customer",
|
||||
party=si.customer,
|
||||
paid_from=debtors2,
|
||||
paid_to="Cash - _TC",
|
||||
paid_amount=1000,
|
||||
)
|
||||
pe.submit()
|
||||
advances = si.get_advance_entries()
|
||||
self.assertEqual(1, len(advances))
|
||||
self.assertEqual(advances[0].reference_name, pe.name)
|
||||
|
||||
def test_taxes_merging_from_delivery_note(self):
|
||||
from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
|
||||
|
||||
dn1 = create_delivery_note(do_not_submit=1)
|
||||
dn1.items[0].qty = 10
|
||||
dn1.items[0].rate = 100
|
||||
dn1.append(
|
||||
"taxes",
|
||||
{
|
||||
"charge_type": "Actual",
|
||||
"account_head": "Freight and Forwarding Charges - _TC",
|
||||
"description": "movement charges",
|
||||
"tax_amount": 100,
|
||||
},
|
||||
)
|
||||
dn1.append(
|
||||
"taxes",
|
||||
{
|
||||
"charge_type": "Actual",
|
||||
"account_head": "Marketing Expenses - _TC",
|
||||
"description": "marketing",
|
||||
"tax_amount": 150,
|
||||
},
|
||||
)
|
||||
dn1.save().submit()
|
||||
|
||||
dn2 = create_delivery_note(do_not_submit=1)
|
||||
dn2.items[0].qty = 5
|
||||
dn2.items[0].rate = 100
|
||||
dn2.append(
|
||||
"taxes",
|
||||
{
|
||||
"charge_type": "Actual",
|
||||
"account_head": "Freight and Forwarding Charges - _TC",
|
||||
"description": "movement charges",
|
||||
"tax_amount": 20,
|
||||
},
|
||||
)
|
||||
dn2.append(
|
||||
"taxes",
|
||||
{
|
||||
"charge_type": "Actual",
|
||||
"account_head": "Miscellaneous Expenses - _TC",
|
||||
"description": "marketing",
|
||||
"tax_amount": 60,
|
||||
},
|
||||
)
|
||||
dn2.save().submit()
|
||||
|
||||
# si = make_sales_invoice(dn1.name)
|
||||
si = create_sales_invoice(do_not_submit=True)
|
||||
si.customer = dn1.customer
|
||||
si.items.clear()
|
||||
|
||||
from frappe.model.mapper import map_docs
|
||||
|
||||
map_docs(
|
||||
method="erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice",
|
||||
source_names=frappe.json.dumps([dn1.name, dn2.name]),
|
||||
target_doc=si,
|
||||
args=frappe.json.dumps({"customer": dn1.customer, "merge_taxes": 1, "filtered_children": []}),
|
||||
)
|
||||
si.save().submit()
|
||||
|
||||
expected = [
|
||||
{
|
||||
"charge_type": "Actual",
|
||||
"account_head": "Freight and Forwarding Charges - _TC",
|
||||
"tax_amount": 120.0,
|
||||
"total": 1520.0,
|
||||
"base_total": 1520.0,
|
||||
},
|
||||
{
|
||||
"charge_type": "Actual",
|
||||
"account_head": "Marketing Expenses - _TC",
|
||||
"tax_amount": 150.0,
|
||||
"total": 1670.0,
|
||||
"base_total": 1670.0,
|
||||
},
|
||||
{
|
||||
"charge_type": "Actual",
|
||||
"account_head": "Miscellaneous Expenses - _TC",
|
||||
"tax_amount": 60.0,
|
||||
"total": 1610.0,
|
||||
"base_total": 1610.0,
|
||||
},
|
||||
]
|
||||
actual = [
|
||||
dict(
|
||||
charge_type=x.charge_type,
|
||||
account_head=x.account_head,
|
||||
tax_amount=x.tax_amount,
|
||||
total=x.total,
|
||||
base_total=x.base_total,
|
||||
)
|
||||
for x in si.taxes
|
||||
]
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
|
||||
def set_advance_flag(company, flag, default_account):
|
||||
frappe.db.set_value(
|
||||
"Company",
|
||||
company,
|
||||
>>>>>>> 39a48a2e2a (test: tax merging from 2 Delivery Note to Sales Invoice)
|
||||
{
|
||||
"item_code": "_Test Item",
|
||||
"uom": "Nos",
|
||||
|
||||
Reference in New Issue
Block a user