|
12 | 12 | from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice |
13 | 13 | from erpnext.accounts.test.accounts_mixin import AccountsTestMixin |
14 | 14 | from erpnext.accounts.utils import get_fiscal_year |
| 15 | +from erpnext.stock.doctype.item.test_item import make_item |
| 16 | +from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries, make_purchase_receipt |
15 | 17 |
|
16 | 18 |
|
17 | 19 | class TestRepostAccountingLedger(AccountsTestMixin, FrappeTestCase): |
@@ -202,9 +204,81 @@ def test_05_without_deletion_flag(self): |
202 | 204 | self.assertIsNotNone(frappe.db.exists("GL Entry", {"voucher_no": si.name, "is_cancelled": 1})) |
203 | 205 | self.assertIsNotNone(frappe.db.exists("GL Entry", {"voucher_no": pe.name, "is_cancelled": 1})) |
204 | 206 |
|
| 207 | + def test_06_repost_purchase_receipt(self): |
| 208 | + from erpnext.accounts.doctype.account.test_account import create_account |
| 209 | + |
| 210 | + provisional_account = create_account( |
| 211 | + account_name="Provision Account", |
| 212 | + parent_account="Current Liabilities - _TC", |
| 213 | + company=self.company, |
| 214 | + ) |
| 215 | + |
| 216 | + another_provisional_account = create_account( |
| 217 | + account_name="Another Provision Account", |
| 218 | + parent_account="Current Liabilities - _TC", |
| 219 | + company=self.company, |
| 220 | + ) |
| 221 | + |
| 222 | + company = frappe.get_doc("Company", self.company) |
| 223 | + company.enable_provisional_accounting_for_non_stock_items = 1 |
| 224 | + company.default_provisional_account = provisional_account |
| 225 | + company.save() |
| 226 | + |
| 227 | + test_cc = company.cost_center |
| 228 | + default_expense_account = company.default_expense_account |
| 229 | + |
| 230 | + item = make_item(properties={"is_stock_item": 0}) |
| 231 | + |
| 232 | + pr = make_purchase_receipt(company=self.company, item_code=item.name, rate=1000.0, qty=1.0) |
| 233 | + pr_gl_entries = get_gl_entries(pr.doctype, pr.name, skip_cancelled=True) |
| 234 | + expected_pr_gles = [ |
| 235 | + {"account": provisional_account, "debit": 0.0, "credit": 1000.0, "cost_center": test_cc}, |
| 236 | + {"account": default_expense_account, "debit": 1000.0, "credit": 0.0, "cost_center": test_cc}, |
| 237 | + ] |
| 238 | + self.assertEqual(expected_pr_gles, pr_gl_entries) |
| 239 | + |
| 240 | + # change the provisional account |
| 241 | + frappe.db.set_value( |
| 242 | + "Purchase Receipt Item", |
| 243 | + pr.items[0].name, |
| 244 | + "provisional_expense_account", |
| 245 | + another_provisional_account, |
| 246 | + ) |
| 247 | + |
| 248 | + repost_doc = frappe.new_doc("Repost Accounting Ledger") |
| 249 | + repost_doc.company = self.company |
| 250 | + repost_doc.delete_cancelled_entries = True |
| 251 | + repost_doc.append("vouchers", {"voucher_type": pr.doctype, "voucher_no": pr.name}) |
| 252 | + repost_doc.save().submit() |
| 253 | + |
| 254 | + pr_gles_after_repost = get_gl_entries(pr.doctype, pr.name, skip_cancelled=True) |
| 255 | + expected_pr_gles_after_repost = [ |
| 256 | + {"account": default_expense_account, "debit": 1000.0, "credit": 0.0, "cost_center": test_cc}, |
| 257 | + {"account": another_provisional_account, "debit": 0.0, "credit": 1000.0, "cost_center": test_cc}, |
| 258 | + ] |
| 259 | + self.assertEqual(len(pr_gles_after_repost), len(expected_pr_gles_after_repost)) |
| 260 | + self.assertEqual(expected_pr_gles_after_repost, pr_gles_after_repost) |
| 261 | + |
| 262 | + # teardown |
| 263 | + repost_doc.cancel() |
| 264 | + repost_doc.delete() |
| 265 | + |
| 266 | + pr.reload() |
| 267 | + pr.cancel() |
| 268 | + |
| 269 | + company.enable_provisional_accounting_for_non_stock_items = 0 |
| 270 | + company.default_provisional_account = None |
| 271 | + company.save() |
| 272 | + |
205 | 273 |
|
206 | 274 | def update_repost_settings(): |
207 | | - allowed_types = ["Sales Invoice", "Purchase Invoice", "Payment Entry", "Journal Entry"] |
| 275 | + allowed_types = [ |
| 276 | + "Sales Invoice", |
| 277 | + "Purchase Invoice", |
| 278 | + "Payment Entry", |
| 279 | + "Journal Entry", |
| 280 | + "Purchase Receipt", |
| 281 | + ] |
208 | 282 | repost_settings = frappe.get_doc("Repost Accounting Ledger Settings") |
209 | 283 | for x in allowed_types: |
210 | 284 | repost_settings.append("allowed_types", {"document_type": x, "allowed": True}) |
|
0 commit comments