reload gross profit report
This commit is contained in:
parent
41207dbec1
commit
6e6dd1b0d5
@ -588,4 +588,12 @@ patch_list = [
|
||||
'patch_module': 'patches.september_2012',
|
||||
'patch_file': 'plot_patch',
|
||||
},
|
||||
{
|
||||
'patch_module': 'patches.september_2012',
|
||||
'patch_file': 'repost_stock',
|
||||
},
|
||||
{
|
||||
'patch_module': 'patches.september_2012',
|
||||
'patch_file': 'reload_gross_profit',
|
||||
},
|
||||
]
|
||||
|
21
erpnext/patches/september_2012/reload_gross_profit.py
Normal file
21
erpnext/patches/september_2012/reload_gross_profit.py
Normal file
@ -0,0 +1,21 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
def execute():
|
||||
# reload gross profit report
|
||||
from webnotes.modules import reload_doc
|
||||
reload_doc('selling', 'search_criteria', 'gross_profit')
|
@ -15,7 +15,7 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.mytabs.items['Select Columns'].hide();
|
||||
//this.mytabs.items['Select Columns'].hide();
|
||||
this.mytabs.tabs['More Filters'].hide();
|
||||
this.hide_all_filters();
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'ID'].df.filter_hide = 0;
|
||||
|
@ -17,6 +17,8 @@
|
||||
# Add Columns
|
||||
# ------------
|
||||
from __future__ import unicode_literals
|
||||
from webnotes.utils import flt
|
||||
|
||||
colnames[colnames.index('Rate*')] = 'Rate'
|
||||
col_idx['Rate'] = col_idx['Rate*']
|
||||
col_idx.pop('Rate*')
|
||||
@ -26,8 +28,8 @@ col_idx.pop('Amount*')
|
||||
|
||||
columns = [
|
||||
['Purchase Cost','Currency','150px',''],
|
||||
['Gross Profit (%)','Currrency','150px',''],
|
||||
['Gross Profit','Currency','150px','']
|
||||
['Gross Profit','Currency','150px',''],
|
||||
['Gross Profit (%)','Currrency','150px','']
|
||||
]
|
||||
|
||||
for c in columns:
|
||||
@ -37,65 +39,46 @@ for c in columns:
|
||||
coloptions.append(c[3])
|
||||
col_idx[c[0]] = len(colnames)-1
|
||||
|
||||
#out, tot_amount, tot_val_amount, tot_gross_profit = [], 0, 0, 0
|
||||
sle = sql("""
|
||||
select
|
||||
item_code, warehouse, posting_date, posting_time,
|
||||
actual_qty, stock_value, voucher_no, voucher_type
|
||||
actual_qty, incoming_rate, voucher_no, item_code, warehouse
|
||||
from
|
||||
`tabStock Ledger Entry`
|
||||
where
|
||||
ifnull(is_cancelled, 'No') = 'No'
|
||||
voucher_type = 'Delivery Note'
|
||||
and ifnull(is_cancelled, 'No') = 'No'
|
||||
order by posting_date desc, posting_time desc, name desc
|
||||
force index posting_sort_index
|
||||
""", as_dict=1)
|
||||
|
||||
def get_purchase_cost(row):
|
||||
stock_value = stock_val_after = 0
|
||||
item_warehouse =
|
||||
def get_purchase_cost(dn, item, wh, qty):
|
||||
from webnotes.utils import flt
|
||||
global sle
|
||||
purchase_cost = 0
|
||||
for d in sle:
|
||||
if d['voucher_type'] == 'Delivery Note' and d['voucher_no'] == row[col_idx['ID']]:
|
||||
stock_val_after += flt(d['stock_value'])
|
||||
if d['voucher_no'] == dn and d['item_code'] == item \
|
||||
and d['warehouse'] == wh and abs(d['actual_qty']) == qty:
|
||||
purchase_cost += flt(d['incoming_rate'])*flt(abs(d['actual_qty']))
|
||||
return purchase_cost
|
||||
|
||||
|
||||
out, tot_amount, tot_pur_cost = [], 0, 0
|
||||
for r in res:
|
||||
r.append(get_purchase_cost(r))
|
||||
purchase_cost = get_purchase_cost(r[col_idx['ID']], r[col_idx['Item Code']], \
|
||||
r[col_idx['Warehouse']], r[col_idx['Quantity']])
|
||||
r.append(purchase_cost)
|
||||
|
||||
gp = flt(r[col_idx['Amount']]) - flt(purchase_cost)
|
||||
gp_percent = purchase_cost and gp*100/purchase_cost or 0
|
||||
r.append(fmt_money(gp))
|
||||
r.append(fmt_money(gp_percent))
|
||||
out.append(r)
|
||||
|
||||
tot_amount += flt(r[col_idx['Amount']])
|
||||
tot_pur_cost += flt(purchase_cost)
|
||||
|
||||
|
||||
# tot_val_rate = 0
|
||||
# packing_list_items = sql("select item_code, warehouse, qty from `tabDelivery Note Packing Item` where parent = %s and parent_item = %s", (r[col_idx['ID']], r[col_idx['Item Code']]))
|
||||
# for d in packing_list_items:
|
||||
# if d[1]:
|
||||
# val_rate = sql("select valuation_rate from `tabStock Ledger Entry` where item_code = %s and warehouse = %s and voucher_type = 'Delivery Note' and voucher_no = %s and is_cancelled = 'No'", (d[0], d[1], r[col_idx['ID']]))
|
||||
# val_rate = val_rate and val_rate[0][0] or 0
|
||||
# if r[col_idx['Quantity']]: tot_val_rate += (flt(val_rate) * flt(d[2]) / flt(r[col_idx['Quantity']]))
|
||||
# else: tot_val_rate = 0
|
||||
#
|
||||
# r.append(fmt_money(tot_val_rate))
|
||||
#
|
||||
# val_amount = flt(tot_val_rate) * flt(r[col_idx['Quantity']])
|
||||
# r.append(fmt_money(val_amount))
|
||||
#
|
||||
# gp = flt(r[col_idx['Amount']]) - flt(val_amount)
|
||||
#
|
||||
# if val_amount: gp_percent = gp * 100 / val_amount
|
||||
# else: gp_percent = gp
|
||||
#
|
||||
# r.append(fmt_money(gp_percent))
|
||||
# r.append(fmt_money(gp))
|
||||
# out.append(r)
|
||||
#
|
||||
# tot_gross_profit += flt(gp)
|
||||
# tot_amount += flt(r[col_idx['Amount']])
|
||||
# tot_val_amount += flt(val_amount)
|
||||
#
|
||||
# Add Total Row
|
||||
# --------------
|
||||
l_row = ['' for i in range(len(colnames))]
|
||||
l_row[col_idx['Quantity']] = '<b>TOTALS</b>'
|
||||
l_row[col_idx['Amount']] = fmt_money(tot_amount)
|
||||
l_row[col_idx['Valuation Amount']] = fmt_money(tot_val_amount)
|
||||
if tot_val_amount: l_row[col_idx['Gross Profit (%)']] = fmt_money((tot_amount - tot_val_amount) * 100 / tot_val_amount)
|
||||
else: l_row[col_idx['Gross Profit (%)']] = fmt_money(tot_amount)
|
||||
l_row[col_idx['Gross Profit']] = fmt_money(tot_gross_profit)
|
||||
l_row[col_idx['Purchase Cost']] = fmt_money(tot_pur_cost)
|
||||
l_row[col_idx['Gross Profit']] = fmt_money(flt(tot_amount) - flt(tot_pur_cost))
|
||||
out.append(l_row)
|
@ -3,23 +3,23 @@
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:51',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:51',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
u'creation': '2012-05-14 18:22:18',
|
||||
u'docstatus': 0,
|
||||
u'modified': '2012-09-24 14:11:39',
|
||||
u'modified_by': u'Administrator',
|
||||
u'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'columns': u'Delivery Note\x01ID,Delivery Note\x01Posting Date,Delivery Note\x01Posting Time,Delivery Note Item\x01Item Code,Delivery Note Item\x01Item Name,Delivery Note Item\x01Description,Delivery Note\x01Project Name,Delivery Note Item\x01Quantity,Delivery Note Item\x01Rate*,Delivery Note Item\x01Amount*',
|
||||
'columns': u'Delivery Note\x01ID,Delivery Note\x01Posting Date,Delivery Note\x01Posting Time,Delivery Note Item\x01Item Code,Delivery Note Item\x01Item Name,Delivery Note Item\x01Description,Delivery Note Item\x01Warehouse,Delivery Note\x01Project Name,Delivery Note Item\x01Quantity,Delivery Note Item\x01Rate*,Delivery Note Item\x01Amount*',
|
||||
'criteria_name': u'Gross Profit',
|
||||
'description': u'Invoice wise',
|
||||
'doc_type': u'Delivery Note Item',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Delivery Note\x01Submitted':1,'Delivery Note\x01Status':'','Delivery Note\x01Fiscal Year':''}",
|
||||
u'doctype': u'Search Criteria',
|
||||
'filters': u'{"Delivery Note\\u0001Submitted":1,"Delivery Note\\u0001Status":[],"Delivery Note\\u0001Fiscal Year":[]}',
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
u'name': u'__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Delivery Note',
|
||||
'sort_by': u'`tabDelivery Note`.`name`',
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
# Search Criteria, gross_profit
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'gross_profit'
|
||||
u'doctype': u'Search Criteria',
|
||||
u'name': u'gross_profit'
|
||||
}
|
||||
]
|
@ -78,7 +78,7 @@ class DocType:
|
||||
|
||||
if sr_count != self.doc.actual_qty:
|
||||
msg = """Actual Qty(%s) in Bin is mismatched with total number(%s)
|
||||
of serial no in store for item: '%s' and warehouse: '%s'""" %
|
||||
of serial no in store for item: %s and warehouse: %s""" % \
|
||||
(self.doc.actual_qty, sr_count, self.doc.item_code, self.doc.warehouse)
|
||||
|
||||
msgprint(msg, raise_exception=1)
|
||||
@ -209,15 +209,17 @@ class DocType:
|
||||
break # nothing in store
|
||||
|
||||
batch = self.fcfs_bal[0]
|
||||
incoming_cost += flt(batch[1])*flt(withdraw)
|
||||
|
||||
if batch[0] <= withdraw:
|
||||
# not enough or exactly same qty in current batch, clear batch
|
||||
incoming_cost += flt(batch[1])*flt(batch[0])
|
||||
withdraw -= batch[0]
|
||||
self.fcfs_bal.pop(0)
|
||||
|
||||
|
||||
else:
|
||||
# all from current batch
|
||||
incoming_cost += flt(batch[1])*flt(withdraw)
|
||||
batch[0] -= withdraw
|
||||
withdraw = 0
|
||||
|
||||
@ -294,7 +296,7 @@ class DocType:
|
||||
prev_sle.get('posting_date','1900-01-01'), \
|
||||
prev_sle.get('posting_time', '12:00')), as_dict = 1)
|
||||
|
||||
for sle in sll:
|
||||
for sle in sll:
|
||||
# block if stock level goes negative on any date
|
||||
if val_method != 'Moving Average' or flt(allow_negative_stock) == 0:
|
||||
self.validate_negative_stock(cqty, sle)
|
||||
@ -309,12 +311,11 @@ class DocType:
|
||||
cqty += sle['actual_qty']
|
||||
# Stock Value upto the sle
|
||||
stock_val = self.get_stock_value(val_method, cqty, val_rate, serial_nos)
|
||||
|
||||
# update current sle
|
||||
sql("""update `tabStock Ledger Entry`
|
||||
set bin_aqat=%s, valuation_rate=%s, fcfs_stack=%s, stock_value=%s, incoming_rate
|
||||
where name=%s""", (cqty, flt(val_rate), cstr(self.fcfs_bal), \
|
||||
stock_val, in_rate, sle['name']))
|
||||
set bin_aqat=%s, valuation_rate=%s, fcfs_stack=%s, stock_value=%s,
|
||||
incoming_rate = %s where name=%s""", \
|
||||
(cqty, flt(val_rate), cstr(self.fcfs_bal), stock_val, in_rate, sle['name']))
|
||||
|
||||
# update the bin
|
||||
if sll or not prev_sle:
|
||||
@ -346,7 +347,7 @@ class DocType:
|
||||
self.create_auto_indent(ret[0], doc_type, doc_name, current_qty[0][0])
|
||||
|
||||
def create_auto_indent(self, i , doc_type, doc_name, cur_qty):
|
||||
""" Create indent on reaching reorder level """\
|
||||
""" Create indent on reaching reorder level """
|
||||
indent = Document('Purchase Request')
|
||||
indent.transaction_date = nowdate()
|
||||
indent.naming_series = 'IDT'
|
||||
|
Loading…
x
Reference in New Issue
Block a user