def execute():
    dataent.reload_doc("stock", "doctype", "bin")
    dataent.reload_doc("buying", "doctype", "purchase_order_item_supplied")
    for d in dataent.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 dataent.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
Пример #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 = dataent.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))
Пример #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)
Пример #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))
Пример #5
0
def update_bin_qty(item_code, warehouse, qty_dict=None):
    from epaas.stock.utils import get_bin
    bin = get_bin(item_code, warehouse)
    mismatch = False
    for fld, val in qty_dict.items():
        if flt(bin.get(fld)) != flt(val):
            bin.set(fld, flt(val))
            mismatch = True

    if mismatch:
        bin.set_projected_qty()
        bin.db_update()
        bin.clear_cache()
Пример #6
0
def execute():
    po_item = list(
        dataent.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

    dataent.reload_doc("stock", "doctype", "bin")
    dataent.reload_doc("buying", "doctype", "purchase_order_item_supplied")
    company_warehouse = dataent._dict(
        dataent.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 = dataent._dict(
        dataent.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)
        dataent.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 = dataent.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
Пример #7
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()
Пример #8
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()