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

This commit is contained in:
Rushabh Mehta 2012-11-06 10:09:10 +01:00
commit 8a92b7d6a6
4 changed files with 46 additions and 21 deletions

View File

@ -46,6 +46,13 @@ cur_frm.cscript.refresh = function(doc,cdt,cdn){
if (doc.docstatus == 0) unhide_field('calculate_total_amount');
}
cur_frm.cscript.validate = function(doc) {
if(cint(doc.docstatus) == 0) {
doc.approval_status = "Draft";
}
cur_frm.cscript.calculate_total(doc);
}
cur_frm.cscript.employee = function(doc,cdt,cdn){
if(doc.employee){
$c_obj(make_doclist(doc.doctype, doc.name),'set_approver','', function(r,rt){

View File

@ -77,10 +77,13 @@ class DocType:
set(self.doc, 'remark', self.doc.remark)
def approve_voucher(self):
missing_count = 0
for d in getlist(self.doclist, 'expense_voucher_details'):
if not d.sanctioned_amount:
msgprint("Please add 'Sanctioned Amount' for all expenses")
return cstr('Incomplete')
missing_count += 1
if missing_count == len(getlist(self.doclist, 'expense_voucher_details')):
msgprint("Please add 'Sanctioned Amount' for atleast one expense")
return cstr('Incomplete')
if not self.doc.total_sanctioned_amount:
msgprint("Please calculate total sanctioned amount using button 'Calculate Total Amount'")
@ -112,7 +115,7 @@ class DocType:
def validate(self):
self.validate_fiscal_year()
def on_update(self):
set(self.doc, 'approval_status', 'Draft')

View File

@ -14,22 +14,26 @@
# You should have received a copy of the GNU General Public License
# 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*')
colnames[colnames.index('Amount*')] = 'Amount'
col_idx['Amount'] = col_idx['Amount*']
col_idx.pop('Amount*')
columns = [
['Purchase Cost','Currency','150px',''],
['Gross Profit','Currency','150px',''],
['Gross Profit (%)','Currrency','150px','']
['Delivery Note', 'Link', '120px', 'Delivery Note'],
['Posting Date', 'Date', '120px', ''],
['Posting Time', 'Data', '120px', ''],
['Item Code', 'Link', '120px', 'Item'],
['Item Name', 'Data', '120px', ''],
['Description', 'Data', '120px', ''],
['Warehouse', 'Link', '120px', 'Warehouse'],
['Project Name', 'Link', '120px', 'Project'],
['Quantity', 'Currency', '120px', ''],
['Rate', 'Currency', '120px', ''],
['Amount', 'Currency', '120px', ''],
#['DN Item Row Id', 'Data', '120px', ''],
['Purchase Cost', 'Currency', '150px', ''],
['Gross Profit', 'Currency', '150px', ''],
['Gross Profit (%)', 'Currrency', '150px', '']
]
for c in columns:
@ -41,7 +45,7 @@ for c in columns:
sle = sql("""
select
actual_qty, incoming_rate, voucher_no, item_code, warehouse
actual_qty, incoming_rate, voucher_no, item_code, warehouse, voucher_detail_no
from
`tabStock Ledger Entry`
where
@ -50,7 +54,7 @@ sle = sql("""
order by posting_date desc, posting_time desc, name desc
""", as_dict=1)
def get_purchase_cost(dn, item, wh, qty):
def get_purchase_cost(dn, item, wh, qty, dn_item_row_id):
from webnotes.utils import flt
global sle
purchase_cost = 0
@ -61,13 +65,15 @@ def get_purchase_cost(dn, item, wh, qty):
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']))
if not d['voucher_detail_no'] or d['voucher_detail_no'] == dn_item_row_id:
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:
purchase_cost = get_purchase_cost(r[col_idx['ID']], r[col_idx['Item Code']], \
r[col_idx['Warehouse']], r[col_idx['Quantity']])
purchase_cost = get_purchase_cost(r[col_idx['Delivery Note']], r[col_idx['Item Code']], \
r[col_idx['Warehouse']], r[col_idx['Quantity']], r[-1])
r.pop(-1)
r.append(purchase_cost)
gp = flt(r[col_idx['Amount']]) - flt(purchase_cost)
@ -79,7 +85,6 @@ for r in res:
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['Project Name']] = '<b>TOTALS</b>'

View File

@ -0,0 +1,10 @@
SELECT
dn.name, dn.posting_date, dn.posting_time, dn_item.item_code,
dn_item.item_name, dn_item.description, dn_item.warehouse,
dn.project_name, dn_item.qty, dn_item.basic_rate, dn_item.amount, dn_item.name
FROM
`tabDelivery Note Item` dn_item, `tabDelivery Note` dn
WHERE
dn.docstatus = 1
AND dn_item.parent = dn.name
ORDER BY dn.name DESC