コード例 #1
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)
コード例 #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", "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
コード例 #3
0
ファイル: gross_profit.py プロジェクト: Anirudh887/erpnext
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