Esempio n. 1
0
def execute():
    from erpnext.stock.stock_balance import get_indented_qty, get_ordered_qty, update_bin_qty

    count = 0
    for item_code, warehouse in frappe.db.sql(
            """select distinct item_code, warehouse from
		(select item_code, warehouse from tabBin
		union
		select item_code, warehouse from `tabStock Ledger Entry`) a"""):
        try:
            if not (item_code and warehouse):
                continue
            count += 1
            update_bin_qty(
                item_code,
                warehouse,
                {
                    "indented_qty": get_indented_qty(item_code, warehouse),
                    "ordered_qty": get_ordered_qty(item_code, warehouse),
                },
            )
            if count % 200 == 0:
                frappe.db.commit()
        except Exception:
            frappe.db.rollback()
Esempio n. 2
0
	def update_ordered_qty(self, po_item_rows=None):
		"""update requested qty (before ordered_qty is updated)"""
		item_wh_list = []
		for d in self.get("items"):
			if (not po_item_rows or d.name in po_item_rows) and [d.item_code, d.warehouse] not in item_wh_list \
					and frappe.db.get_value("Item", d.item_code, "is_stock_item") and d.warehouse:
				item_wh_list.append([d.item_code, d.warehouse])

		for item_code, warehouse in item_wh_list:
			update_bin_qty(item_code, warehouse, {
				"ordered_qty": get_ordered_qty(item_code, warehouse)
			})
Esempio n. 3
0
    def update_ordered_qty(self, po_item_rows=None):
        """update requested qty (before ordered_qty is updated)"""
        item_wh_list = []
        for d in self.get("items"):
            if (not po_item_rows or d.name in po_item_rows) and [d.item_code, d.warehouse] not in item_wh_list \
              and frappe.db.get_value("Item", d.item_code, "is_stock_item") and d.warehouse:
                item_wh_list.append([d.item_code, d.warehouse])

        for item_code, warehouse in item_wh_list:
            update_bin_qty(
                item_code, warehouse,
                {"ordered_qty": get_ordered_qty(item_code, warehouse)})
def delete_and_patch_duplicate_bins():

    duplicate_bins = frappe.db.sql(
        """
		SELECT
			item_code, warehouse, count(*) as bin_count
		FROM
			tabBin
		GROUP BY
			item_code, warehouse
		HAVING
			bin_count > 1
	""",
        as_dict=1,
    )

    for duplicate_bin in duplicate_bins:
        item_code = duplicate_bin.item_code
        warehouse = duplicate_bin.warehouse
        existing_bins = frappe.get_list(
            "Bin",
            filters={
                "item_code": item_code,
                "warehouse": warehouse
            },
            fields=["name"],
            order_by="creation",
        )

        # keep last one
        existing_bins.pop()

        for broken_bin in existing_bins:
            frappe.delete_doc("Bin", broken_bin.name)

        qty_dict = {
            "reserved_qty": get_reserved_qty(item_code, warehouse),
            "indented_qty": get_indented_qty(item_code, warehouse),
            "ordered_qty": get_ordered_qty(item_code, warehouse),
            "planned_qty": get_planned_qty(item_code, warehouse),
            "actual_qty": get_balance_qty_from_sle(item_code, warehouse),
        }

        bin = get_bin(item_code, warehouse)
        bin.update(qty_dict)
        bin.update_reserved_qty_for_production()
        bin.update_reserved_qty_for_sub_contracting()
        bin.db_update()
def execute():
	from erpnext.stock.stock_balance import update_bin_qty, get_indented_qty, get_ordered_qty

	count=0
	for item_code, warehouse in frappe.db.sql("""select distinct item_code, warehouse from
		(select item_code, warehouse from tabBin
		union
		select item_code, warehouse from `tabStock Ledger Entry`) a"""):
			try:
				count += 1
				update_bin_qty(item_code, warehouse, {
					"indented_qty": get_indented_qty(item_code, warehouse),
					"ordered_qty": get_ordered_qty(item_code, warehouse)
				})
				if count % 200 == 0:
					frappe.db.commit()
			except:
				frappe.db.rollback()