def get_incoming_rate(self, args): incoming_rate = 0 if self.doc.purpose == "Sales Return" and \ (self.doc.delivery_note_no or self.doc.sales_invoice_no): sle = webnotes.conn.sql( """select name, posting_date, posting_time, actual_qty, stock_value, warehouse from `tabStock Ledger Entry` where voucher_type = %s and voucher_no = %s and item_code = %s limit 1""", ((self.doc.delivery_note_no and "Delivery Note" or "Sales Invoice"), self.doc.delivery_note_no or self.doc.sales_invoice_no, args.item_code), as_dict=1) if sle: args.update({ "posting_date": sle[0].posting_date, "posting_time": sle[0].posting_time, "sle": sle[0].name, "warehouse": sle[0].warehouse, }) previous_sle = get_previous_sle(args) incoming_rate = (flt(sle[0].stock_value) - flt(previous_sle.get("stock_value"))) / \ flt(sle[0].actual_qty) else: incoming_rate = get_incoming_rate(args) return incoming_rate
def get_incoming_rate(self, args): incoming_rate = 0 if self.doc.purpose == "Sales Return" and (self.doc.delivery_note_no or self.doc.sales_invoice_no): sle = webnotes.conn.sql( """select name, posting_date, posting_time, actual_qty, stock_value, warehouse from `tabStock Ledger Entry` where voucher_type = %s and voucher_no = %s and item_code = %s and ifnull(is_cancelled, 'No') = 'No' limit 1""", ( (self.doc.delivery_note_no and "Delivery Note" or "Sales Invoice"), self.doc.delivery_note_no or self.doc.sales_invoice_no, args.item_code, ), as_dict=1, ) if sle: args.update( { "posting_date": sle[0].posting_date, "posting_time": sle[0].posting_time, "sle": sle[0].name, "warehouse": sle[0].warehouse, } ) previous_sle = get_previous_sle(args) incoming_rate = (flt(sle[0].stock_value) - flt(previous_sle.get("stock_value"))) / flt( sle[0].actual_qty ) else: incoming_rate = get_incoming_rate(args) return incoming_rate
def get_valuation_rate(self, args): """ Get average valuation rate of relevant warehouses as per valuation method (MAR/FIFO) as on costing date """ from stock.utils import get_incoming_rate dt = self.doc.costing_date or nowdate() time = self.doc.costing_date == nowdate() and now().split( )[1] or '23:59' warehouse = webnotes.conn.sql( "select warehouse from `tabBin` where item_code = %s", args['item_code']) rate = [] for wh in warehouse: r = get_incoming_rate({ "item_code": args.get("item_code"), "warehouse": wh[0], "posting_date": dt, "posting_time": time, "qty": args.get("qty") or 0 }) if r: rate.append(r) return rate and flt(sum(rate)) / len(rate) or 0
def get_warehouse_details(self, args): import json args, actual_qty, in_rate = json.loads(args), 0, 0 args.update({ "posting_date": self.doc.posting_date, "posting_time": self.doc.posting_time }) ret = { "actual_qty" : get_previous_sle(args).get("qty_after_transaction") or 0, "incoming_rate" : get_incoming_rate(args) } return ret
def get_stock_and_rate(self): """get stock and incoming rate on posting date""" for d in getlist(self.doclist, 'mtn_details'): args = { "item_code": d.item_code, "warehouse": d.s_warehouse or d.t_warehouse, "posting_date": self.doc.posting_date, "posting_time": self.doc.posting_time, "qty": d.transfer_qty, "serial_no": d.serial_no, "bom_no": d.bom_no } # get actual stock at source warehouse d.actual_qty = get_previous_sle(args).get("qty_after_transaction") or 0 # get incoming rate if not flt(d.incoming_rate): d.incoming_rate = get_incoming_rate(args) d.amount = flt(d.qty) * flt(d.incoming_rate)
def get_valuation_rate(self, args): """ Get average valuation rate of relevant warehouses as per valuation method (MAR/FIFO) as on costing date """ from stock.utils import get_incoming_rate dt = self.doc.costing_date or nowdate() time = self.doc.costing_date == nowdate() and now().split()[1] or '23:59' warehouse = sql("select warehouse from `tabBin` where item_code = %s", args['item_code']) rate = [] for wh in warehouse: r = get_incoming_rate({ "item_code": args.get("item_code"), "warehouse": wh[0], "posting_date": dt, "posting_time": time, "qty": args.get("qty") or 0 }) if r: rate.append(r) return rate and flt(sum(rate))/len(rate) or 0