Esempio n. 1
0
    def test_sales_invoice_gl_entry_with_aii_non_stock_item(self):
        self.clear_stock_account_balance()
        set_perpetual_inventory()
        si_copy = frappe.copy_doclist(test_records[1])
        si_copy[1]["item_code"] = "_Test Non Stock Item"
        si = frappe.bean(si_copy)
        si.insert()
        si.submit()

        gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
			order by account asc""",
                                   si.doc.name,
                                   as_dict=1)
        self.assertTrue(gl_entries)

        expected_values = sorted([
            [si.doc.debit_to, 630.0, 0.0],
            [test_records[1][1]["income_account"], 0.0, 500.0],
            [test_records[1][2]["account_head"], 0.0, 80.0],
            [test_records[1][3]["account_head"], 0.0, 50.0],
        ])
        for i, gle in enumerate(gl_entries):
            self.assertEquals(expected_values[i][0], gle.account)
            self.assertEquals(expected_values[i][1], gle.debit)
            self.assertEquals(expected_values[i][2], gle.credit)

        set_perpetual_inventory(0)
Esempio n. 2
0
    def test_si_gl_entry_with_aii_and_update_stock_with_warehouse_but_no_account(
            self):
        self.clear_stock_account_balance()
        set_perpetual_inventory()
        frappe.delete_doc("Account", "_Test Warehouse No Account - _TC")

        # insert purchase receipt
        from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import test_records \
         as pr_test_records
        pr = frappe.bean(copy=pr_test_records[0])
        pr.doc.naming_series = "_T-Purchase Receipt-"
        pr.doclist[1].warehouse = "_Test Warehouse No Account - _TC"
        pr.insert()
        pr.submit()

        si_doclist = frappe.copy_doclist(test_records[1])
        si_doclist[0]["update_stock"] = 1
        si_doclist[0]["posting_time"] = "12:05"
        si_doclist[1]["warehouse"] = "_Test Warehouse No Account - _TC"

        si = frappe.bean(copy=si_doclist)
        si.insert()
        si.submit()

        # check stock ledger entries
        sle = frappe.db.sql("""select * from `tabStock Ledger Entry` 
			where voucher_type = 'Sales Invoice' and voucher_no = %s""",
                            si.doc.name,
                            as_dict=1)[0]
        self.assertTrue(sle)
        self.assertEquals(
            [sle.item_code, sle.warehouse, sle.actual_qty],
            ["_Test Item", "_Test Warehouse No Account - _TC", -1.0])

        # check gl entries
        gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
			order by account asc, debit asc""",
                                   si.doc.name,
                                   as_dict=1)
        self.assertTrue(gl_entries)

        expected_gl_entries = sorted([
            [si.doc.debit_to, 630.0, 0.0],
            [si_doclist[1]["income_account"], 0.0, 500.0],
            [si_doclist[2]["account_head"], 0.0, 80.0],
            [si_doclist[3]["account_head"], 0.0, 50.0],
        ])
        for i, gle in enumerate(gl_entries):
            self.assertEquals(expected_gl_entries[i][0], gle.account)
            self.assertEquals(expected_gl_entries[i][1], gle.debit)
            self.assertEquals(expected_gl_entries[i][2], gle.credit)

        si.cancel()
        gle = frappe.db.sql(
            """select * from `tabGL Entry` 
			where voucher_type='Sales Invoice' and voucher_no=%s""", si.doc.name)

        self.assertFalse(gle)
        set_perpetual_inventory(0)
Esempio n. 3
0
    def test_time_log_batch(self):
        tlb = frappe.bean("Time Log Batch", "_T-Time Log Batch-00001")
        tlb.submit()

        si = frappe.bean(frappe.copy_doclist(test_records[0]))
        si.doclist[1].time_log_batch = "_T-Time Log Batch-00001"
        si.insert()
        si.submit()

        self.assertEquals(
            frappe.db.get_value("Time Log Batch", "_T-Time Log Batch-00001",
                                "status"), "Billed")

        self.assertEquals(
            frappe.db.get_value("Time Log", "_T-Time Log-00001", "status"),
            "Billed")

        si.cancel()

        self.assertEquals(
            frappe.db.get_value("Time Log Batch", "_T-Time Log Batch-00001",
                                "status"), "Submitted")

        self.assertEquals(
            frappe.db.get_value("Time Log", "_T-Time Log-00001", "status"),
            "Batched for Billing")
Esempio n. 4
0
    def test_reserved_qty_for_partial_delivery_with_packing_list(self):
        from erpnext.selling.doctype.sales_bom.test_sales_bom import test_records as sbom_test_records

        # change item in test so record

        test_record = frappe.copy_doclist(test_records[0])
        test_record[1]["item_code"] = "_Test Sales BOM Item"

        # reset bin
        self.delete_bin(sbom_test_records[0][1]["item_code"],
                        test_record[1]["warehouse"])
        self.delete_bin(sbom_test_records[0][2]["item_code"],
                        test_record[1]["warehouse"])

        # submit
        so = self.create_so(test_record)

        # allow negative stock
        frappe.db.set_default("allow_negative_stock", 1)

        # submit dn
        dn = self.create_dn_against_so(so)

        self.check_reserved_qty(sbom_test_records[0][1]["item_code"],
                                so.doclist[1].warehouse, 25.0)
        self.check_reserved_qty(sbom_test_records[0][2]["item_code"],
                                so.doclist[1].warehouse, 10.0)

        # stop so
        so.load_from_db()
        so.obj.stop_sales_order()

        self.check_reserved_qty(sbom_test_records[0][1]["item_code"],
                                so.doclist[1].warehouse, 0.0)
        self.check_reserved_qty(sbom_test_records[0][2]["item_code"],
                                so.doclist[1].warehouse, 0.0)

        # unstop so
        so.load_from_db()
        so.obj.unstop_sales_order()
        self.check_reserved_qty(sbom_test_records[0][1]["item_code"],
                                so.doclist[1].warehouse, 25.0)
        self.check_reserved_qty(sbom_test_records[0][2]["item_code"],
                                so.doclist[1].warehouse, 10.0)

        # cancel dn
        dn.cancel()
        self.check_reserved_qty(sbom_test_records[0][1]["item_code"],
                                so.doclist[1].warehouse, 50.0)
        self.check_reserved_qty(sbom_test_records[0][2]["item_code"],
                                so.doclist[1].warehouse, 20.0)
Esempio n. 5
0
    def create_dn_against_so(self, so, delivered_qty=0):
        from erpnext.stock.doctype.delivery_note.test_delivery_note import test_records as dn_test_records
        from erpnext.stock.doctype.delivery_note.test_delivery_note import _insert_purchase_receipt

        _insert_purchase_receipt(so.doclist[1].item_code)

        dn = frappe.bean(frappe.copy_doclist(dn_test_records[0]))
        dn.doclist[1].item_code = so.doclist[1].item_code
        dn.doclist[1].against_sales_order = so.doc.name
        dn.doclist[1].prevdoc_detail_docname = so.doclist[1].name
        if delivered_qty:
            dn.doclist[1].qty = delivered_qty
        dn.insert()
        dn.submit()
        return dn
Esempio n. 6
0
    def test_payment(self):
        frappe.db.sql("""delete from `tabGL Entry`""")
        w = self.make()

        from erpnext.accounts.doctype.journal_voucher.test_journal_voucher \
         import test_records as jv_test_records

        jv = frappe.bean(frappe.copy_doclist(jv_test_records[0]))
        jv.doclist[1].against_invoice = w.doc.name
        jv.insert()
        jv.submit()

        self.assertEquals(
            frappe.db.get_value("Sales Invoice", w.doc.name,
                                "outstanding_amount"), 161.8)

        jv.cancel()
        self.assertEquals(
            frappe.db.get_value("Sales Invoice", w.doc.name,
                                "outstanding_amount"), 561.8)
Esempio n. 7
0
    def test_reserved_qty_for_over_delivery_with_packing_list(self):
        from erpnext.selling.doctype.sales_bom.test_sales_bom import test_records as sbom_test_records

        # change item in test so record
        test_record = frappe.copy_doclist(test_records[0])
        test_record[1]["item_code"] = "_Test Sales BOM Item"

        # reset bin
        self.delete_bin(sbom_test_records[0][1]["item_code"],
                        test_record[1]["warehouse"])
        self.delete_bin(sbom_test_records[0][2]["item_code"],
                        test_record[1]["warehouse"])

        # submit
        so = self.create_so(test_record)

        # allow negative stock
        frappe.db.set_default("allow_negative_stock", 1)

        # set over-delivery tolerance
        frappe.db.set_value('Item', so.doclist[1].item_code, 'tolerance', 50)

        # submit dn
        dn = self.create_dn_against_so(so, 15)

        self.check_reserved_qty(sbom_test_records[0][1]["item_code"],
                                so.doclist[1].warehouse, 0.0)
        self.check_reserved_qty(sbom_test_records[0][2]["item_code"],
                                so.doclist[1].warehouse, 0.0)

        # cancel dn
        dn.cancel()
        self.check_reserved_qty(sbom_test_records[0][1]["item_code"],
                                so.doclist[1].warehouse, 50.0)
        self.check_reserved_qty(sbom_test_records[0][2]["item_code"],
                                so.doclist[1].warehouse, 20.0)
Esempio n. 8
0
    def test_pos_gl_entry_with_aii(self):
        self.clear_stock_account_balance()
        set_perpetual_inventory()

        self._insert_purchase_receipt()
        self._insert_pos_settings()

        pos = frappe.copy_doclist(test_records[1])
        pos[0]["is_pos"] = 1
        pos[0]["update_stock"] = 1
        pos[0]["posting_time"] = "12:05"
        pos[0]["cash_bank_account"] = "_Test Account Bank Account - _TC"
        pos[0]["paid_amount"] = 600.0

        si = frappe.bean(copy=pos)
        si.insert()
        si.submit()

        # check stock ledger entries
        sle = frappe.db.sql("""select * from `tabStock Ledger Entry` 
			where voucher_type = 'Sales Invoice' and voucher_no = %s""",
                            si.doc.name,
                            as_dict=1)[0]
        self.assertTrue(sle)
        self.assertEquals([sle.item_code, sle.warehouse, sle.actual_qty],
                          ["_Test Item", "_Test Warehouse - _TC", -1.0])

        # check gl entries
        gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
			order by account asc, debit asc""",
                                   si.doc.name,
                                   as_dict=1)
        self.assertTrue(gl_entries)

        stock_in_hand = frappe.db.get_value(
            "Account", {"master_name": "_Test Warehouse - _TC"})

        expected_gl_entries = sorted(
            [[si.doc.debit_to, 630.0, 0.0],
             [pos[1]["income_account"], 0.0, 500.0],
             [pos[2]["account_head"], 0.0, 80.0],
             [pos[3]["account_head"], 0.0, 50.0], [stock_in_hand, 0.0, 75.0],
             [pos[1]["expense_account"], 75.0, 0.0],
             [si.doc.debit_to, 0.0, 600.0],
             ["_Test Account Bank Account - _TC", 600.0, 0.0]])
        for i, gle in enumerate(gl_entries):
            self.assertEquals(expected_gl_entries[i][0], gle.account)
            self.assertEquals(expected_gl_entries[i][1], gle.debit)
            self.assertEquals(expected_gl_entries[i][2], gle.credit)

        si.cancel()
        gle = frappe.db.sql(
            """select * from `tabGL Entry` 
			where voucher_type='Sales Invoice' and voucher_no=%s""", si.doc.name)

        self.assertFalse(gle)

        self.assertFalse(get_stock_and_account_difference([stock_in_hand]))

        set_perpetual_inventory(0)
Esempio n. 9
0
 def test_duplication(self):
     ts = frappe.bean(frappe.copy_doclist(test_records[0]))
     self.assertRaises(OverlapError, ts.insert)