Exemple #1
0
def repost_actual_qty(item_code, warehouse, allow_zero_rate=False):
    try:
        update_entries_after({
            "item_code": item_code,
            "warehouse": warehouse
        }, allow_zero_rate)
    except:
        pass
def set_valuation_method(item_code, valuation_method):
    dataent.db.set_value("Item", item_code, "valuation_method",
                         valuation_method)

    for warehouse in dataent.get_all("Warehouse",
                                     filters={"company": "_Test Company"},
                                     fields=["name", "is_group"]):
        if not warehouse.is_group:
            update_entries_after(
                {
                    "item_code": item_code,
                    "warehouse": warehouse.name
                },
                allow_negative_stock=1)
Exemple #3
0
def execute():
	try:
		year_start_date = get_fiscal_year(today())[1]
	except:
		return
	
	if year_start_date:
		items = dataent.db.sql("""select distinct item_code, warehouse from `tabStock Ledger Entry` 
			where ifnull(serial_no, '') != '' and actual_qty > 0 and incoming_rate=0""", as_dict=1)
		
		for d in items:
			try:
				update_entries_after({
					"item_code": d.item_code, 
					"warehouse": d.warehouse,
					"posting_date": year_start_date
				}, allow_zero_rate=True)
			except:
				pass
Exemple #4
0
	def update_stock(self, args, allow_negative_stock=False, via_landed_cost_voucher=False):
		'''Called from epaas.stock.utils.update_bin'''
		self.update_qty(args)

		if args.get("actual_qty") or args.get("voucher_type") == "Stock Reconciliation":
			from epaas.stock.stock_ledger import update_entries_after

			if not args.get("posting_date"):
				args["posting_date"] = nowdate()

			# update valuation and qty after transaction for post dated entry
			if args.get("is_cancelled") == "Yes" and via_landed_cost_voucher:
				return
			update_entries_after({
				"item_code": self.item_code,
				"warehouse": self.warehouse,
				"posting_date": args.get("posting_date"),
				"posting_time": args.get("posting_time"),
				"voucher_no": args.get("voucher_no")
			}, allow_negative_stock=allow_negative_stock, via_landed_cost_voucher=via_landed_cost_voucher)
Exemple #5
0
    def delete_and_repost_sle(self):
        """	Delete Stock Ledger Entries related to this voucher
			and repost future Stock Ledger Entries"""

        existing_entries = dataent.db.sql(
            """select distinct item_code, warehouse
			from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s""",
            (self.doctype, self.name),
            as_dict=1)

        # delete entries
        dataent.db.sql(
            """delete from `tabStock Ledger Entry`
			where voucher_type=%s and voucher_no=%s""", (self.doctype, self.name))

        # repost future entries for selected item_code, warehouse
        for entries in existing_entries:
            update_entries_after({
                "item_code": entries.item_code,
                "warehouse": entries.warehouse,
                "posting_date": self.posting_date,
                "posting_time": self.posting_time
            })
Exemple #6
0
def set_stock_balance_as_per_serial_no(item_code=None,
                                       posting_date=None,
                                       posting_time=None,
                                       fiscal_year=None):
    if not posting_date: posting_date = nowdate()
    if not posting_time: posting_time = nowtime()

    condition = " and item.name='%s'" % item_code.replace(
        "'", "\'") if item_code else ""

    bin = dataent.db.sql(
        """select bin.item_code, bin.warehouse, bin.actual_qty, item.stock_uom
		from `tabBin` bin, tabItem item
		where bin.item_code = item.name and item.has_serial_no = 1 %s""" % condition)

    for d in bin:
        serial_nos = dataent.db.sql(
            """select count(name) from `tabSerial No`
			where item_code=%s and warehouse=%s and docstatus < 2""", (d[0], d[1]))

        if serial_nos and flt(serial_nos[0][0]) != flt(d[2]):
            print(d[0], d[1], d[2], serial_nos[0][0])

        sle = dataent.db.sql(
            """select valuation_rate, company from `tabStock Ledger Entry`
			where item_code = %s and warehouse = %s and ifnull(is_cancelled, 'No') = 'No'
			order by posting_date desc limit 1""", (d[0], d[1]))

        sle_dict = {
            'doctype':
            'Stock Ledger Entry',
            'item_code':
            d[0],
            'warehouse':
            d[1],
            'transaction_date':
            nowdate(),
            'posting_date':
            posting_date,
            'posting_time':
            posting_time,
            'voucher_type':
            'Stock Reconciliation (Manual)',
            'voucher_no':
            '',
            'voucher_detail_no':
            '',
            'actual_qty':
            flt(serial_nos[0][0]) - flt(d[2]),
            'stock_uom':
            d[3],
            'incoming_rate':
            sle and flt(serial_nos[0][0]) > flt(d[2]) and flt(sle[0][0]) or 0,
            'company':
            sle and cstr(sle[0][1]) or 0,
            'is_cancelled':
            'No',
            'batch_no':
            '',
            'serial_no':
            ''
        }

        sle_doc = dataent.get_doc(sle_dict)
        sle_doc.flags.ignore_validate = True
        sle_doc.flags.ignore_links = True
        sle_doc.insert()

        args = sle_dict.copy()
        args.update({"sle_id": sle_doc.name, "is_amended": 'No'})

        update_bin(args)
        update_entries_after({
            "item_code": d[0],
            "warehouse": d[1],
            "posting_date": posting_date,
            "posting_time": posting_time
        })