예제 #1
0
    def set_buying_amount(self, stock_ledger_entries=None):
        from stock.utils import get_buying_amount

        if not stock_ledger_entries:
            stock_ledger_entries = self.get_stock_ledger_entries()

        item_sales_bom = {}
        for d in self.doclist.get({"parentfield": "packing_details"}):
            new_d = webnotes._dict(d.fields.copy())
            new_d.total_qty = -1 * d.qty
            item_sales_bom.setdefault(d.parent_item, []).append(new_d)

        if stock_ledger_entries:
            for item in self.doclist.get({"parentfield": self.fname}):
                if item.item_code in self.stock_items or (item_sales_bom and item_sales_bom.get(item.item_code)):
                    buying_amount = get_buying_amount(
                        item.item_code,
                        item.warehouse,
                        -1 * item.qty,
                        self.doc.doctype,
                        self.doc.name,
                        item.name,
                        stock_ledger_entries,
                        item_sales_bom,
                    )
                    item.buying_amount = buying_amount > 0 and buying_amount or 0
                    webnotes.conn.set_value(item.doctype, item.name, "buying_amount", item.buying_amount)
예제 #2
0
def execute(filters=None):
	if not filters: filters = {}
	
	stock_ledger_entries = get_stock_ledger_entries(filters)
	
	source = get_source_data(filters)
	
	item_sales_bom = get_item_sales_bom()
	
	columns = ["Delivery Note/Sales Invoice::120", "Posting Date:Date", "Posting Time", 
		"Item Code:Link/Item", "Item Name", "Description", "Warehouse:Link/Warehouse",
		"Qty:Float", "Selling Rate:Currency", "Selling Amount:Currency", "Buying Amount:Currency",
		"Gross Profit:Currency", "Gross Profit %:Percent", "Project:Link/Project"]
	
	data = []
	for row in source:
		selling_amount = flt(row.amount)
		buying_amount = get_buying_amount(row.item_code, row.warehouse, -1*row.qty, 
			row.parenttype, row.name, row.item_row, stock_ledger_entries, 
			item_sales_bom.get(row.parenttype, {}).get(row.name, webnotes._dict()))
		
		buying_amount = buying_amount > 0 and buying_amount or 0
		
		if selling_amount:
			gross_profit = selling_amount - buying_amount
			gross_profit_percent = (gross_profit / selling_amount) * 100.0
		else:
			gross_profit = gross_profit_percent = 0.0
		
		name = """<a href="%s">%s</a>""" % ("/".join(["#Form", row.parenttype, row.name]), row.name)
		data.append([name, row.posting_date, row.posting_time, row.item_code, row.item_name,
			row.description, row.warehouse, row.qty, row.basic_rate, row.amount, buying_amount,
			gross_profit, gross_profit_percent, row.project])
			
	return columns, data
예제 #3
0
	def set_buying_amount(self, stock_ledger_entries = None):
		from stock.utils import get_buying_amount, get_sales_bom_buying_amount
		if not stock_ledger_entries:
			stock_ledger_entries = self.get_stock_ledger_entries()

		item_sales_bom = {}
		for d in self.doclist.get({"parentfield": "packing_details"}):
			new_d = webnotes._dict(d.fields.copy())
			new_d.total_qty = -1 * d.qty
			item_sales_bom.setdefault(d.parent_item, []).append(new_d)
		
		if stock_ledger_entries:
			for item in self.doclist.get({"parentfield": self.fname}):
				if item.item_code in self.stock_items or \
						(item_sales_bom and item_sales_bom.get(item.item_code)):
					
					buying_amount = 0
					if item.item_code in self.stock_items:
						buying_amount = get_buying_amount(self.doc.doctype, self.doc.name, 
							item.name, stock_ledger_entries.get((item.item_code, 
								item.warehouse), []))
					elif item_sales_bom and item_sales_bom.get(item.item_code):
						buying_amount = get_sales_bom_buying_amount(item.item_code, item.warehouse, 
							self.doc.doctype, self.doc.name, item.name, stock_ledger_entries, 
							item_sales_bom)
					
					# buying_amount >= 0.01 so that gl entry doesn't get created for such small amounts
					item.buying_amount = buying_amount >= 0.01 and buying_amount or 0
					webnotes.conn.set_value(item.doctype, item.name, "buying_amount", 
						item.buying_amount)
예제 #4
0
def execute(filters=None):
	if not filters: filters = {}
	
	stock_ledger_entries = get_stock_ledger_entries(filters)
	item_sales_bom = get_sales_bom()
	
	delivery_note_items = webnotes.conn.sql("""select dn.name, dn.posting_date, dn.posting_time,
		dn.project_name, item.item_code, item.item_name, item.description, item.warehouse,
		item.qty, item.basic_rate, item.amount, item.name as "item_row"
		from `tabDelivery Note` dn, `tabDelivery Note Item` item
		where item.parent = dn.name and dn.docstatus = 1
		order by dn.posting_date desc, dn.posting_time desc""", as_dict=1)
	
	columns = ["Delivery Note:Link/Delivery Note", "Posting Date:Date", "Posting Time", 
		"Item Code:Link/Item", "Item Name", "Description", "Warehouse:Link/Warehouse",
		"Qty:Float", "Selling Rate:Currency", "Selling Amount:Currency", "Buying Amount:Currency",
		"Gross Profit:Currency", "Gross Profit %:Percent", "Project:Link/Project"]
		
	data = []
	for row in delivery_note_items:
		selling_amount = flt(row.amount)
		buying_amount = get_buying_amount(row.item_code, row.warehouse, 
			row.qty, "Delivery Note", row.name, row.item_row, stock_ledger_entries, item_sales_bom)
		if selling_amount:
			gross_profit = selling_amount - buying_amount
			gross_profit_percent = (gross_profit / selling_amount) * 100.0
		else:
			gross_profit = gross_profit_percent = 0.0
		
		data.append([row.name, row.posting_date, row.posting_time, row.item_code, row.item_name,
			row.description, row.warehouse, row.qty, row.basic_rate, row.amount, buying_amount,
			gross_profit, gross_profit_percent, row.project])
			
	return columns, data
예제 #5
0
	def set_stock_value_difference(self):
		"""stock_value_difference is the increment in the stock value"""
		from stock.utils import get_buying_amount
		
		item_list = [d.item_code for d in self.entries]
		warehouse_list = [d.warehouse for d in self.entries]
		stock_ledger_entries = self.get_stock_ledger_entries(item_list, warehouse_list)
		
		self.doc.stock_value_difference = 0.0
		for d in self.entries:
			self.doc.stock_value_difference -= get_buying_amount(d.item_code, d.warehouse, 
				d.actual_qty, self.doc.doctype, self.doc.name, d.voucher_detail_no, 
				stock_ledger_entries)
		webnotes.conn.set(self.doc, "stock_value_difference", self.doc.stock_value_difference)
예제 #6
0
	def set_stock_value_difference(self):
		"""stock_value_difference is the increment in the stock value"""
		from stock.utils import get_buying_amount
		
		item_list = [d.item_code for d in self.entries]
		warehouse_list = [d.warehouse for d in self.entries]
		stock_ledger_entries = self.get_stock_ledger_entries(item_list, warehouse_list)
		
		self.doc.stock_value_difference = 0.0
		for d in self.entries:
			self.doc.stock_value_difference -= get_buying_amount(d.item_code, d.warehouse, 
				d.actual_qty, self.doc.doctype, self.doc.name, d.voucher_detail_no, 
				stock_ledger_entries)
		webnotes.conn.set(self.doc, "stock_value_difference", self.doc.stock_value_difference)
예제 #7
0
	def get_item_buying_amount(self, item, stock_ledger_entries, item_sales_bom):
		item_buying_amount = 0
		if stock_ledger_entries:
			# is pos and update stock
			item_buying_amount = get_buying_amount(item.item_code, item.warehouse, item.qty, 
				self.doc.doctype, self.doc.name, item.name, stock_ledger_entries, item_sales_bom)
		elif item.delivery_note and item.dn_detail:
			# against delivery note
			dn_item = webnotes.conn.get_value("Delivery Note Item", item.dn_detail, 
				["buying_amount", "qty"], as_dict=1)
			item_buying_rate = flt(dn_item.buying_amount) / flt(dn_item.qty)
			item_buying_amount = item_buying_rate * flt(item.qty)
		
		return item_buying_amount
예제 #8
0
	def set_buying_amount(self):
		from stock.utils import get_buying_amount, get_sales_bom
		stock_ledger_entries = self.get_stock_ledger_entries()
		item_sales_bom = get_sales_bom()
		
		if stock_ledger_entries:
			for item in self.doclist.get({"parentfield": "delivery_note_details"}):
				item.buying_amount = get_buying_amount(item.item_code, item.warehouse, item.qty, 
					self.doc.doctype, self.doc.name, item.name, stock_ledger_entries, 
					item_sales_bom)
				webnotes.conn.set_value("Delivery Note Item", item.name, "buying_amount", 
					item.buying_amount)
		
		self.validate_warehouse()
예제 #9
0
def execute(filters=None):
    if not filters: filters = {}

    stock_ledger_entries = get_stock_ledger_entries(filters)
    source = get_source_data(filters)
    item_sales_bom = get_item_sales_bom()

    columns = [
        "Delivery Note/Sales Invoice::120", "Link::30", "Posting Date:Date",
        "Posting Time", "Item Code:Link/Item", "Item Name", "Description",
        "Warehouse:Link/Warehouse", "Qty:Float", "Selling Rate:Currency",
        "Avg. Buying Rate:Currency", "Selling Amount:Currency",
        "Buying Amount:Currency", "Gross Profit:Currency",
        "Gross Profit %:Percent", "Project:Link/Project"
    ]
    data = []
    for row in source:
        selling_amount = flt(row.amount)

        item_sales_bom_map = item_sales_bom.get(row.parenttype, {}).get(
            row.name, webnotes._dict())

        if item_sales_bom_map.get(row.item_code):
            buying_amount = get_sales_bom_buying_amount(
                row.item_code, row.warehouse, row.parenttype, row.name,
                row.item_row, stock_ledger_entries, item_sales_bom_map)
        else:
            buying_amount = get_buying_amount(
                row.parenttype, row.name, row.item_row,
                stock_ledger_entries.get((row.item_code, row.warehouse), []))

        buying_amount = buying_amount > 0 and buying_amount or 0

        gross_profit = selling_amount - buying_amount
        if selling_amount:
            gross_profit_percent = (gross_profit / selling_amount) * 100.0
        else:
            gross_profit_percent = 0.0

        icon = """<a href="%s"><i class="icon icon-share" style="cursor: pointer;"></i></a>""" \
         % ("/".join(["#Form", row.parenttype, row.name]),)
        data.append([
            row.name, icon, row.posting_date, row.posting_time, row.item_code,
            row.item_name, row.description, row.warehouse, row.qty,
            row.basic_rate, row.qty and (buying_amount / row.qty) or 0,
            row.amount, buying_amount, gross_profit, gross_profit_percent,
            row.project
        ])

    return columns, data
	def set_stock_value_difference(self):
		"""stock_value_difference is the increment in the stock value"""
		from stock.utils import get_buying_amount
		
		item_list = [d.item_code for d in self.entries]
		warehouse_list = [d.warehouse for d in self.entries]
		if not (item_list and warehouse_list):
			webnotes.throw(_("Invalid Item or Warehouse Data"))
		
		stock_ledger_entries = self.get_stock_ledger_entries(item_list, warehouse_list)
		
		self.doc.stock_value_difference = 0.0
		for d in self.entries:
			self.doc.stock_value_difference -= get_buying_amount(self.doc.doctype, self.doc.name,
				d.voucher_detail_no, stock_ledger_entries.get((d.item_code, d.warehouse), []))
		webnotes.conn.set(self.doc, "stock_value_difference", self.doc.stock_value_difference)
    def set_stock_value_difference(self):
        """stock_value_difference is the increment in the stock value"""
        from stock.utils import get_buying_amount

        item_list = [d.item_code for d in self.entries]
        warehouse_list = [d.warehouse for d in self.entries]
        if not (item_list and warehouse_list):
            webnotes.throw(_("Invalid Item or Warehouse Data"))

        stock_ledger_entries = self.get_stock_ledger_entries(
            item_list, warehouse_list)

        self.doc.stock_value_difference = 0.0
        for d in self.entries:
            self.doc.stock_value_difference -= get_buying_amount(
                self.doc.doctype, self.doc.name, d.voucher_detail_no,
                stock_ledger_entries.get((d.item_code, d.warehouse), []))
        webnotes.conn.set(self.doc, "stock_value_difference",
                          self.doc.stock_value_difference)
예제 #12
0
def execute(filters=None):
	if not filters: filters = {}
	
	stock_ledger_entries = get_stock_ledger_entries(filters)
	source = get_source_data(filters)
	item_sales_bom = get_item_sales_bom()
	
	columns = ["Delivery Note/Sales Invoice::120", "Link::30", "Posting Date:Date", "Posting Time", 
		"Item Code:Link/Item", "Item Name", "Description", "Warehouse:Link/Warehouse",
		"Qty:Float", "Selling Rate:Currency", "Avg. Buying Rate:Currency", 
		"Selling Amount:Currency", "Buying Amount:Currency",
		"Gross Profit:Currency", "Gross Profit %:Percent", "Project:Link/Project"]
	data = []
	for row in source:
		selling_amount = flt(row.amount)
		
		item_sales_bom_map = item_sales_bom.get(row.parenttype, {}).get(row.name, webnotes._dict())
		
		if item_sales_bom_map.get(row.item_code):
			buying_amount = get_sales_bom_buying_amount(row.item_code, row.warehouse, 
				row.parenttype, row.name, row.item_row, stock_ledger_entries, item_sales_bom_map)
		else:
			buying_amount = get_buying_amount(row.parenttype, row.name, row.item_row,
				stock_ledger_entries.get((row.item_code, row.warehouse), []))
		
		buying_amount = buying_amount > 0 and buying_amount or 0

		gross_profit = selling_amount - buying_amount
		if selling_amount:
			gross_profit_percent = (gross_profit / selling_amount) * 100.0
		else:
			gross_profit_percent = 0.0
		
		icon = """<a href="%s"><i class="icon icon-share" style="cursor: pointer;"></i></a>""" \
			% ("/".join(["#Form", row.parenttype, row.name]),)
		data.append([row.name, icon, row.posting_date, row.posting_time, row.item_code, row.item_name,
			row.description, row.warehouse, row.qty, row.basic_rate, 
			row.qty and (buying_amount / row.qty) or 0, row.amount, buying_amount,
			gross_profit, gross_profit_percent, row.project])
			
	return columns, data