Exemplo n.º 1
0
    def test_delivery_note_cost_center_with_balance_sheet_account(self):
        cost_center = "Main - TCP1"

        company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company')

        set_valuation_method("_Test Item", "FIFO")

        make_stock_entry(target="Stores - TCP1", qty=5, basic_rate=100)

        stock_in_hand_account = get_inventory_account(
            '_Test Company with perpetual inventory')
        dn = create_delivery_note(
            company='_Test Company with perpetual inventory',
            warehouse='Stores - TCP1',
            cost_center='Main - TCP1',
            expense_account="Cost of Goods Sold - TCP1",
            do_not_submit=1)

        dn.get('items')[0].cost_center = None
        dn.submit()

        gl_entries = get_gl_entries("Delivery Note", dn.name)

        self.assertTrue(gl_entries)
        expected_values = {
            "Cost of Goods Sold - TCP1": {
                "cost_center": cost_center
            },
            stock_in_hand_account: {
                "cost_center": cost_center
            }
        }
        for i, gle in enumerate(gl_entries):
            self.assertEqual(expected_values[gle.account]["cost_center"],
                             gle.cost_center)
Exemplo n.º 2
0
    def test_delivery_note_with_cost_center(self):
        from erpbee.accounts.doctype.cost_center.test_cost_center import create_cost_center
        cost_center = "_Test Cost Center for BS Account - TCP1"
        create_cost_center(cost_center_name="_Test Cost Center for BS Account",
                           company="_Test Company with perpetual inventory")

        company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company')

        set_valuation_method("_Test Item", "FIFO")

        make_stock_entry(target="Stores - TCP1", qty=5, basic_rate=100)

        stock_in_hand_account = get_inventory_account(
            '_Test Company with perpetual inventory')
        dn = create_delivery_note(
            company='_Test Company with perpetual inventory',
            warehouse='Stores - TCP1',
            expense_account="Cost of Goods Sold - TCP1",
            cost_center=cost_center)

        gl_entries = get_gl_entries("Delivery Note", dn.name)
        self.assertTrue(gl_entries)

        expected_values = {
            "Cost of Goods Sold - TCP1": {
                "cost_center": cost_center
            },
            stock_in_hand_account: {
                "cost_center": cost_center
            }
        }
        for i, gle in enumerate(gl_entries):
            self.assertEqual(expected_values[gle.account]["cost_center"],
                             gle.cost_center)
Exemplo n.º 3
0
	def test_landed_cost_voucher(self):
		frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1)

		pr = make_purchase_receipt(company="_Test Company with perpetual inventory",
			warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1",
			get_multiple_items = True, get_taxes_and_charges = True)

		last_sle = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pr.doctype,
				"voucher_no": pr.name,
				"item_code": "_Test Item",
				"warehouse": "Stores - TCP1"
			},
			fieldname=["qty_after_transaction", "stock_value"], as_dict=1)

		create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company)

		pr_lc_value = frappe.db.get_value("Purchase Receipt Item", {"parent": pr.name}, "landed_cost_voucher_amount")
		self.assertEqual(pr_lc_value, 25.0)

		last_sle_after_landed_cost = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pr.doctype,
				"voucher_no": pr.name,
				"item_code": "_Test Item",
				"warehouse": "Stores - TCP1"
			},
			fieldname=["qty_after_transaction", "stock_value"], as_dict=1)

		self.assertEqual(last_sle.qty_after_transaction, last_sle_after_landed_cost.qty_after_transaction)

		self.assertEqual(last_sle_after_landed_cost.stock_value - last_sle.stock_value, 25.0)

		gl_entries = get_gl_entries("Purchase Receipt", pr.name)

		self.assertTrue(gl_entries)

		stock_in_hand_account = get_inventory_account(pr.company, pr.get("items")[0].warehouse)
		fixed_asset_account = get_inventory_account(pr.company, pr.get("items")[1].warehouse)

		if stock_in_hand_account == fixed_asset_account:
			expected_values = {
				stock_in_hand_account: [800.0, 0.0],
				"Stock Received But Not Billed - TCP1": [0.0, 500.0],
				"Expenses Included In Valuation - TCP1": [0.0, 50.0],
				"_Test Account Customs Duty - TCP1": [0.0, 150],
				"_Test Account Shipping Charges - TCP1": [0.0, 100.00]
			}
		else:
			expected_values = {
				stock_in_hand_account: [400.0, 0.0],
				fixed_asset_account: [400.0, 0.0],
				"Stock Received But Not Billed - TCP1": [0.0, 500.0],
				"Expenses Included In Valuation - TCP1": [0.0, 300.0]
			}

		for gle in gl_entries:
			if not gle.get('is_cancelled'):
				self.assertEqual(expected_values[gle.account][0], gle.debit)
				self.assertEqual(expected_values[gle.account][1], gle.credit)
Exemplo n.º 4
0
    def test_delivery_note_gl_entry_packing_item(self):
        company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company')

        make_stock_entry(item_code="_Test Item",
                         target="Stores - TCP1",
                         qty=10,
                         basic_rate=100)
        make_stock_entry(item_code="_Test Item Home Desktop 100",
                         target="Stores - TCP1",
                         qty=10,
                         basic_rate=100)

        stock_in_hand_account = get_inventory_account(
            '_Test Company with perpetual inventory')
        prev_bal = get_balance_on(stock_in_hand_account)

        dn = create_delivery_note(
            item_code="_Test Product Bundle Item",
            company='_Test Company with perpetual inventory',
            warehouse='Stores - TCP1',
            cost_center='Main - TCP1',
            expense_account="Cost of Goods Sold - TCP1")

        stock_value_diff_rm1 = abs(
            frappe.db.get_value(
                "Stock Ledger Entry", {
                    "voucher_type": "Delivery Note",
                    "voucher_no": dn.name,
                    "item_code": "_Test Item"
                }, "stock_value_difference"))

        stock_value_diff_rm2 = abs(
            frappe.db.get_value(
                "Stock Ledger Entry", {
                    "voucher_type": "Delivery Note",
                    "voucher_no": dn.name,
                    "item_code": "_Test Item Home Desktop 100"
                }, "stock_value_difference"))

        stock_value_diff = stock_value_diff_rm1 + stock_value_diff_rm2

        gl_entries = get_gl_entries("Delivery Note", dn.name)
        self.assertTrue(gl_entries)

        expected_values = {
            stock_in_hand_account: [0.0, stock_value_diff],
            "Cost of Goods Sold - TCP1": [stock_value_diff, 0.0]
        }
        for i, gle in enumerate(gl_entries):
            self.assertEqual([gle.debit, gle.credit],
                             expected_values.get(gle.account))

        # check stock in hand balance
        bal = get_balance_on(stock_in_hand_account)
        self.assertEqual(flt(bal, 2), flt(prev_bal - stock_value_diff, 2))

        dn.cancel()
Exemplo n.º 5
0
	def test_landed_cost_voucher_against_purchase_invoice(self):

		pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(),
			posting_time=frappe.utils.nowtime(), cash_bank_account="Cash - TCP1",
			company="_Test Company with perpetual inventory", supplier_warehouse="Work In Progress - TCP1",
			warehouse= "Stores - TCP1", cost_center = "Main - TCP1",
			expense_account ="_Test Account Cost for Goods Sold - TCP1")

		last_sle = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pi.doctype,
				"voucher_no": pi.name,
				"item_code": "_Test Item",
				"warehouse": "Stores - TCP1"
			},
			fieldname=["qty_after_transaction", "stock_value"], as_dict=1)

		create_landed_cost_voucher("Purchase Invoice", pi.name, pi.company)

		pi_lc_value = frappe.db.get_value("Purchase Invoice Item", {"parent": pi.name},
			"landed_cost_voucher_amount")

		self.assertEqual(pi_lc_value, 50.0)

		last_sle_after_landed_cost = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pi.doctype,
				"voucher_no": pi.name,
				"item_code": "_Test Item",
				"warehouse": "Stores - TCP1"
			},
			fieldname=["qty_after_transaction", "stock_value"], as_dict=1)

		self.assertEqual(last_sle.qty_after_transaction, last_sle_after_landed_cost.qty_after_transaction)

		self.assertEqual(last_sle_after_landed_cost.stock_value - last_sle.stock_value, 50.0)

		gl_entries = get_gl_entries("Purchase Invoice", pi.name)

		self.assertTrue(gl_entries)
		stock_in_hand_account = get_inventory_account(pi.company, pi.get("items")[0].warehouse)

		expected_values = {
			stock_in_hand_account: [300.0, 0.0],
			"Creditors - TCP1": [0.0, 250.0],
			"Expenses Included In Valuation - TCP1": [0.0, 50.0]
		}

		for gle in gl_entries:
			if not gle.get('is_cancelled'):
				self.assertEqual(expected_values[gle.account][0], gle.debit)
				self.assertEqual(expected_values[gle.account][1], gle.credit)
Exemplo n.º 6
0
    def test_gl_entries_in_base_currency(self):
        inv = create_sales_invoice(rate=200)
        inv_disc = create_invoice_discounting(
            [inv.name],
            accounts_receivable_credit=self.ar_credit,
            accounts_receivable_discounted=self.ar_discounted,
            accounts_receivable_unpaid=self.ar_unpaid,
            short_term_loan=self.short_term_loan,
            bank_charges_account=self.bank_charges_account,
            bank_account=self.bank_account)

        gle = get_gl_entries("Invoice Discounting", inv_disc.name)

        expected_gle = {inv.debit_to: [0.0, 200], self.ar_credit: [200, 0.0]}
        for i, gle in enumerate(gle):
            self.assertEqual([gle.debit, gle.credit],
                             expected_gle.get(gle.account))
Exemplo n.º 7
0
    def test_delivery_note_no_gl_entry(self):
        company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC',
                                      'company')
        make_stock_entry(target="_Test Warehouse - _TC", qty=5, basic_rate=100)

        stock_queue = json.loads(
            get_previous_sle({
                "item_code": "_Test Item",
                "warehouse": "_Test Warehouse - _TC",
                "posting_date": nowdate(),
                "posting_time": nowtime()
            }).stock_queue or "[]")

        dn = create_delivery_note()

        sle = frappe.get_doc("Stock Ledger Entry", {
            "voucher_type": "Delivery Note",
            "voucher_no": dn.name
        })

        self.assertEqual(sle.stock_value_difference,
                         flt(-1 * stock_queue[0][1], 2))

        self.assertFalse(get_gl_entries("Delivery Note", dn.name))
Exemplo n.º 8
0
    def test_delivery_of_bundled_items_to_target_warehouse(self):
        company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company')

        set_valuation_method("_Test Item", "FIFO")
        set_valuation_method("_Test Item Home Desktop 100", "FIFO")

        target_warehouse = get_warehouse(
            company=company,
            abbr="TCP1",
            warehouse_name="_Test Customer Warehouse").name

        for warehouse in ("Stores - TCP1", target_warehouse):
            create_stock_reconciliation(
                item_code="_Test Item",
                warehouse=warehouse,
                company=company,
                expense_account="Stock Adjustment - TCP1",
                qty=500,
                rate=100)
            create_stock_reconciliation(
                item_code="_Test Item Home Desktop 100",
                company=company,
                expense_account="Stock Adjustment - TCP1",
                warehouse=warehouse,
                qty=500,
                rate=100)

        dn = create_delivery_note(
            item_code="_Test Product Bundle Item",
            company='_Test Company with perpetual inventory',
            cost_center='Main - TCP1',
            expense_account="Cost of Goods Sold - TCP1",
            do_not_submit=True,
            qty=5,
            rate=500,
            warehouse="Stores - TCP1",
            target_warehouse=target_warehouse)

        dn.submit()

        # qty after delivery
        actual_qty_at_source = get_qty_after_transaction(
            warehouse="Stores - TCP1")
        self.assertEqual(actual_qty_at_source, 475)

        actual_qty_at_target = get_qty_after_transaction(
            warehouse=target_warehouse)
        self.assertEqual(actual_qty_at_target, 525)

        # stock value diff for source warehouse for "_Test Item"
        stock_value_difference = frappe.db.get_value(
            "Stock Ledger Entry", {
                "voucher_type": "Delivery Note",
                "voucher_no": dn.name,
                "item_code": "_Test Item",
                "warehouse": "Stores - TCP1"
            }, "stock_value_difference")

        # stock value diff for target warehouse
        stock_value_difference1 = frappe.db.get_value(
            "Stock Ledger Entry", {
                "voucher_type": "Delivery Note",
                "voucher_no": dn.name,
                "item_code": "_Test Item",
                "warehouse": target_warehouse
            }, "stock_value_difference")

        self.assertEqual(abs(stock_value_difference), stock_value_difference1)

        # Check gl entries
        gl_entries = get_gl_entries("Delivery Note", dn.name)
        self.assertTrue(gl_entries)

        stock_value_difference = abs(
            frappe.db.sql(
                """select sum(stock_value_difference)
			from `tabStock Ledger Entry` where voucher_type='Delivery Note' and voucher_no=%s
			and warehouse='Stores - TCP1'""", dn.name)[0][0])

        expected_values = {
            "Stock In Hand - TCP1": [0.0, stock_value_difference],
            target_warehouse: [stock_value_difference, 0.0]
        }
        for i, gle in enumerate(gl_entries):
            self.assertEqual([gle.debit, gle.credit],
                             expected_values.get(gle.account))