def execute():
    frappe.reload_doc("stock", "doctype", "bin")
    frappe.reload_doc("buying", "doctype", "purchase_order_item_supplied")
    for d in frappe.db.sql("""
		select distinct rm_item_code, reserve_warehouse
		from `tabPurchase Order Item Supplied`
		where docstatus=1 and reserve_warehouse is not null and reserve_warehouse != ''"""
                           ):

        try:
            bin_doc = get_bin(d[0], d[1])
            bin_doc.update_reserved_qty_for_sub_contracting()
        except:
            pass

    for d in frappe.db.sql("""select distinct item_code, source_warehouse
		from `tabWork Order Item`
		where docstatus=1 and transferred_qty > required_qty
			and source_warehouse is not null and source_warehouse != ''""",
                           as_list=1):

        try:
            bin_doc = get_bin(d[0], d[1])
            bin_doc.update_reserved_qty_for_production()
        except:
            pass
Esempio n. 2
0
    def test_reserved_qty_for_stopped_production(self):
        test_stock_entry.make_stock_entry(item_code="_Test Item",
                                          target=self.warehouse,
                                          qty=100,
                                          basic_rate=100)
        test_stock_entry.make_stock_entry(
            item_code="_Test Item Home Desktop 100",
            target=self.warehouse,
            qty=100,
            basic_rate=100)

        # 	0 0 0

        self.test_reserved_qty_for_production_submit()

        #2 0 -2

        s = frappe.get_doc(
            make_stock_entry(self.wo_order.name,
                             "Material Transfer for Manufacture", 1))

        s.submit()

        #1 -1 0

        bin1_on_start_production = get_bin(self.item, self.warehouse)

        # reserved_qty_for_producion updated
        self.assertEqual(
            cint(self.bin1_at_start.reserved_qty_for_production) + 1,
            cint(bin1_on_start_production.reserved_qty_for_production))

        # projected qty will now be 2 less (becuase of item movement)
        self.assertEqual(cint(self.bin1_at_start.projected_qty),
                         cint(bin1_on_start_production.projected_qty) + 2)

        # STOP
        stop_unstop(self.wo_order.name, "Stopped")

        bin1_on_stop_production = get_bin(self.item, self.warehouse)

        # no change in reserved / projected
        self.assertEqual(
            cint(bin1_on_stop_production.reserved_qty_for_production),
            cint(self.bin1_at_start.reserved_qty_for_production))
        self.assertEqual(
            cint(bin1_on_stop_production.projected_qty) + 1,
            cint(self.bin1_at_start.projected_qty))
Esempio n. 3
0
    def test_reserved_qty_for_production_submit(self):
        self.bin1_at_start = get_bin(self.item, self.warehouse)

        # reset to correct value
        self.bin1_at_start.update_reserved_qty_for_production()

        self.wo_order = make_wo_order_test_record(
            item="_Test FG Item", qty=2, source_warehouse=self.warehouse)

        self.bin1_on_submit = get_bin(self.item, self.warehouse)

        # reserved qty for production is updated
        self.assertEqual(
            cint(self.bin1_at_start.reserved_qty_for_production) + 2,
            cint(self.bin1_on_submit.reserved_qty_for_production))
        self.assertEqual(cint(self.bin1_at_start.projected_qty),
                         cint(self.bin1_on_submit.projected_qty) + 2)
Esempio n. 4
0
    def test_reserved_qty_for_production_cancel(self):
        self.test_reserved_qty_for_production_submit()

        self.wo_order.cancel()

        bin1_on_cancel = get_bin(self.item, self.warehouse)

        # reserved_qty_for_producion updated
        self.assertEqual(cint(self.bin1_at_start.reserved_qty_for_production),
                         cint(bin1_on_cancel.reserved_qty_for_production))
        self.assertEqual(self.bin1_at_start.projected_qty,
                         cint(bin1_on_cancel.projected_qty))
Esempio n. 5
0
    def update_bin(self):
        # update bin for each warehouse
        for warehouse, data in iteritems(self.data):
            bin_doc = get_bin(self.item_code, warehouse)

            bin_doc.update({
                "valuation_rate": data.valuation_rate,
                "actual_qty": data.qty_after_transaction,
                "stock_value": data.stock_value
            })
            bin_doc.flags.via_stock_ledger_entry = True
            bin_doc.save(ignore_permissions=True)
Esempio n. 6
0
def update_bin_qty(item_code, warehouse, qty_dict=None):
    from erpbee.stock.utils import get_bin
    bin = get_bin(item_code, warehouse)
    mismatch = False
    for field, value in qty_dict.items():
        if flt(bin.get(field)) != flt(value):
            bin.set(field, flt(value))
            mismatch = True

    if mismatch:
        bin.set_projected_qty()
        bin.db_update()
        bin.clear_cache()
Esempio n. 7
0
    def test_resered_qty_for_partial_completion(self):
        item = "_Test Item"
        warehouse = create_warehouse("Test Warehouse for reserved_qty - _TC")

        bin1_at_start = get_bin(item, warehouse)

        # reset to correct value
        bin1_at_start.update_reserved_qty_for_production()

        wo_order = make_wo_order_test_record(item="_Test FG Item",
                                             qty=2,
                                             source_warehouse=warehouse,
                                             skip_transfer=1)

        bin1_on_submit = get_bin(item, warehouse)

        # reserved qty for production is updated
        self.assertEqual(
            cint(bin1_at_start.reserved_qty_for_production) + 2,
            cint(bin1_on_submit.reserved_qty_for_production))

        test_stock_entry.make_stock_entry(item_code="_Test Item",
                                          target=warehouse,
                                          qty=100,
                                          basic_rate=100)
        test_stock_entry.make_stock_entry(
            item_code="_Test Item Home Desktop 100",
            target=warehouse,
            qty=100,
            basic_rate=100)

        s = frappe.get_doc(make_stock_entry(wo_order.name, "Manufacture", 1))
        s.submit()

        bin1_at_completion = get_bin(item, warehouse)

        self.assertEqual(cint(bin1_at_completion.reserved_qty_for_production),
                         cint(bin1_on_submit.reserved_qty_for_production) - 1)
Esempio n. 8
0
def execute():
	po_item = list(frappe.db.sql(("""
		select distinct po.name as poname, poitem.rm_item_code as rm_item_code, po.company
		from `tabPurchase Order` po, `tabPurchase Order Item Supplied` poitem
		where po.name = poitem.parent
			and po.is_subcontracted = "Yes"
			and po.docstatus = 1"""), as_dict=1))
	if not po_item:
		return

	frappe.reload_doc("stock", "doctype", "bin")
	frappe.reload_doc("buying", "doctype", "purchase_order_item_supplied")
	company_warehouse = frappe._dict(frappe.db.sql("""select company, min(name) from `tabWarehouse`
		where is_group = 0 group by company"""))

	items = list(set([d.rm_item_code for d in po_item]))
	item_wh = frappe._dict(frappe.db.sql("""select item_code, default_warehouse
		from `tabItem` where name in ({0})""".format(", ".join(["%s"] * len(items))), items))

	# Update reserved warehouse
	for item in po_item:
		reserve_warehouse = get_warehouse(item.rm_item_code, item.company, company_warehouse, item_wh)
		frappe.db.sql("""update `tabPurchase Order Item Supplied`
			set reserve_warehouse = %s
			where parent = %s and rm_item_code = %s
		""", (reserve_warehouse, item["poname"], item["rm_item_code"]))

	# Update bin
	item_wh_bin = frappe.db.sql(("""
		select distinct poitemsup.rm_item_code as rm_item_code,
			poitemsup.reserve_warehouse as reserve_warehouse
		from `tabPurchase Order` po, `tabPurchase Order Item Supplied` poitemsup
		where po.name = poitemsup.parent
			and po.is_subcontracted = "Yes"
			and po.docstatus = 1"""), as_dict=1)
	for d in item_wh_bin:
		try:
			stock_bin = get_bin(d["rm_item_code"], d["reserve_warehouse"])
			stock_bin.update_reserved_qty_for_sub_contracting()
		except:
			pass
Esempio n. 9
0
 def update_reserved_qty_for_production(self, items=None):
     '''update reserved_qty_for_production in bins'''
     for d in self.required_items:
         if d.source_warehouse:
             stock_bin = get_bin(d.item_code, d.source_warehouse)
             stock_bin.update_reserved_qty_for_production()
Esempio n. 10
0
 def update_reserved_qty_for_subcontract(self):
     for d in self.supplied_items:
         if d.rm_item_code:
             stock_bin = get_bin(d.rm_item_code, d.reserve_warehouse)
             stock_bin.update_reserved_qty_for_sub_contracting()