Merge branch 'master' of github.com:webnotes/erpnext into 1209

Conflicts:
	public/js/all-app.js
	public/js/all-web.js
This commit is contained in:
Anand Doshi
2012-09-26 12:24:28 +05:30
11 changed files with 441 additions and 315 deletions

View File

@@ -8,15 +8,17 @@
#
# 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
# 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/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# 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*')
@@ -24,55 +26,66 @@ colnames[colnames.index('Amount*')] = 'Amount'
col_idx['Amount'] = col_idx['Amount*']
col_idx.pop('Amount*')
columns = [['Valuation Rate','Currency','150px',''],
['Valuation Amount','Currency','150px',''],
['Gross Profit (%)','Currrency','150px',''],
['Gross Profit','Currency','150px','']]
columns = [
['Purchase Cost','Currency','150px',''],
['Gross Profit','Currency','150px',''],
['Gross Profit (%)','Currrency','150px','']
]
for c in columns:
colnames.append(c[0])
coltypes.append(c[1])
colwidths.append(c[2])
coloptions.append(c[3])
col_idx[c[0]] = len(colnames)-1
colnames.append(c[0])
coltypes.append(c[1])
colwidths.append(c[2])
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
actual_qty, incoming_rate, voucher_no, item_code, warehouse
from
`tabStock Ledger Entry`
where
voucher_type = 'Delivery Note'
and ifnull(is_cancelled, 'No') = 'No'
order by posting_date desc, posting_time desc, name desc
""", as_dict=1)
def get_purchase_cost(dn, item, wh, qty):
from webnotes.utils import flt
global sle
purchase_cost = 0
packing_items = sql("select item_code, qty from `tabSales BOM Item` where parent = %s", item)
if packing_items:
packing_items = [[t[0], flt(t[1])*qty] for t in packing_items]
else:
packing_items = [[item, qty]]
for d in sle:
if d['voucher_no'] == dn and [d['item_code'], flt(abs(d['actual_qty']))] in packing_items:
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:
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)
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 = r[col_idx['Amount']] and purchase_cost and \
round((gp*100/flt(r[col_idx['Amount']])), 2) 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)
# Add Total Row
# --------------
l_row = ['' for i in range(len(colnames))]
l_row[col_idx['Quantity']] = '<b>TOTALS</b>'
l_row[col_idx['Project Name']] = '<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))
l_row[col_idx['Gross Profit (%)']] = tot_amount and \
round((flt(tot_amount) - flt(tot_pur_cost))*100 / flt(tot_amount), 2)
out.append(l_row)

View File

@@ -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'
}
]