Merge branch 'sales_purchase_return'

This commit is contained in:
Anand Doshi
2013-03-19 16:23:11 +05:30
57 changed files with 938 additions and 1398 deletions

View File

@@ -32,209 +32,3 @@ def get_default_bank_account():
WHERE name=%s AND docstatus<2""", company)
if res: return res[0][0]
@webnotes.whitelist()
def get_new_jv_details():
"""
Get details which will help create new jv on sales/purchase return
"""
doclist = webnotes.form_dict.get('doclist')
fiscal_year = webnotes.form_dict.get('fiscal_year')
if not (isinstance(doclist, basestring) and isinstance(fiscal_year, basestring)): return
import json
doclist = json.loads(doclist)
doc, children = doclist[0], doclist[1:]
if doc.get('return_type')=='Sales Return':
if doc.get('sales_invoice_no'):
return get_invoice_details(doc, children, fiscal_year)
elif doc.get('delivery_note_no'):
return get_delivery_note_details(doc, children, fiscal_year)
elif doc.get('purchase_receipt_no'):
return get_purchase_receipt_details(doc, children, fiscal_year)
def get_invoice_details(doc, children, fiscal_year):
"""
Gets details from an invoice to make new jv
Returns [{
'account': ,
'balance': ,
'debit': ,
'credit': ,
'against_invoice': ,
'against_payable':
}, { ... }, ...]
"""
if doc.get('return_type')=='Sales Return':
obj = get_obj('Sales Invoice', doc.get('sales_invoice_no'), with_children=1)
else:
obj = get_obj('Purchase Invoice', doc.get('purchase_invoice_no'), with_children=1)
if not obj.doc.docstatus==1: return
# Build invoice account jv detail record
invoice_rec = get_invoice_account_jv_record(doc, children, fiscal_year, obj)
# Build item accountwise jv detail records
item_accountwise_list = get_item_accountwise_jv_record(doc, children, fiscal_year, obj)
return [invoice_rec] + item_accountwise_list
def get_invoice_account_jv_record(doc, children, fiscal_year, obj):
"""
Build customer/supplier account jv detail record
"""
# Calculate total return amount
total_amt = sum([(flt(ch.get('rate')) * flt(ch.get('returned_qty'))) for ch in children])
ret = {}
if doc.get('return_type')=='Sales Return':
account = obj.doc.debit_to
ret['against_invoice'] = doc.get('sales_invoice_no')
ret['credit'] = total_amt
else:
account = obj.doc.credit_to
ret['against_voucher'] = doc.get('purchase_invoice_no')
ret['debit'] = total_amt
ret.update({
'account': account,
'balance': get_balance_on(account, doc.get("return_date"))
})
return ret
def get_item_accountwise_jv_record(doc, children, fiscal_year, obj):
"""
Build item accountwise jv detail records
"""
if doc.get('return_type')=='Sales Return':
amt_field = 'debit'
ac_field = 'income_account'
else:
amt_field = 'credit'
ac_field = 'expense_head'
inv_children = dict([[ic.fields.get('item_code'), ic] for ic in obj.doclist if ic.fields.get('item_code')])
accwise_list = []
for ch in children:
inv_ch = inv_children.get(ch.get('item_code'))
if not inv_ch: continue
amount = flt(ch.get('rate')) * flt(ch.get('returned_qty'))
accounts = [[jvd['account'], jvd['cost_center']] for jvd in accwise_list]
if [inv_ch.fields.get(ac_field), inv_ch.fields.get('cost_center')] not in accounts:
rec = {
'account': inv_ch.fields.get(ac_field),
'cost_center': inv_ch.fields.get('cost_center'),
'balance': get_balance_on(inv_ch.fields.get(ac_field),
doc.get("return_date"))
}
rec[amt_field] = amount
accwise_list.append(rec)
else:
rec = accwise_list[accounts.index([inv_ch.fields.get(ac_field), inv_ch.fields.get('cost_center')])]
rec[amt_field] = rec[amt_field] + amount
return accwise_list
def get_jv_details_from_inv_list(doc, children, fiscal_year, inv_list, jv_details_list):
"""
Get invoice details and make jv detail records
"""
for inv in inv_list:
if not inv[0]: continue
if doc.get('return_type')=='Sales Return':
doc['sales_invoice_no'] = inv[0]
else:
doc['purchase_invoice_no'] = inv[0]
jv_details = get_invoice_details(doc, children, fiscal_year)
if jv_details and len(jv_details)>1: jv_details_list.extend(jv_details)
return jv_details_list
def get_prev_doc_list(obj, prev_doctype):
"""
Returns a list of previous doc's names
"""
prevdoc_list = []
for ch in obj.doclist:
if ch.fields.get('prevdoc_docname') and ch.fields.get('prevdoc_doctype')==prev_doctype:
prevdoc_list.append(ch.fields.get('prevdoc_docname'))
return prevdoc_list
def get_inv_list(table, field, value):
"""
Returns invoice list
"""
if isinstance(value, basestring):
return webnotes.conn.sql("""\
SELECT DISTINCT parent FROM `%s`
WHERE %s='%s' AND docstatus=1""" % (table, field, value))
elif isinstance(value, list):
return webnotes.conn.sql("""\
SELECT DISTINCT parent FROM `%s`
WHERE %s IN ("%s") AND docstatus=1""" % (table, field, '", "'.join(value)))
else:
return []
def get_delivery_note_details(doc, children, fiscal_year):
"""
Gets sales invoice numbers from delivery note details
and returns detail records for jv
"""
jv_details_list = []
dn_obj = get_obj('Delivery Note', doc['delivery_note_no'], with_children=1)
inv_list = get_inv_list('tabSales Invoice Item', 'delivery_note', doc['delivery_note_no'])
if inv_list:
jv_details_list = get_jv_details_from_inv_list(doc, children, fiscal_year, inv_list, jv_details_list)
if not (inv_list and jv_details_list):
so_list = get_prev_doc_list(dn_obj, 'Sales Order')
inv_list = get_inv_list('tabSales Invoice Item', 'sales_order', so_list)
if inv_list:
jv_details_list = get_jv_details_from_inv_list(doc, children, fiscal_year, inv_list, jv_details_list)
return jv_details_list
def get_purchase_receipt_details(doc, children, fiscal_year):
"""
Gets purchase invoice numbers from purchase receipt details
and returns detail records for jv
"""
jv_details_list = []
pr_obj = get_obj('Purchase Receipt', doc['purchase_receipt_no'], with_children=1)
inv_list = get_inv_list('tabPurchase Invoice Item', 'purchase_receipt', doc['purchase_receipt_no'])
if inv_list:
jv_details_list = get_jv_details_from_inv_list(doc, children, fiscal_year, inv_list, jv_details_list)
if not (inv_list and jv_details_list):
po_list = get_prev_doc_list(pr_obj, 'Purchase Order')
inv_list = get_inv_list('tabPurchase Invoice Item', 'purchase_order', po_list)
if inv_list:
jv_details_list = get_jv_details_from_inv_list(doc, children, fiscal_year, inv_list, jv_details_list)
return jv_details_list

View File

@@ -0,0 +1,14 @@
test_records = [
[{
"doctype": "POS Setting",
"name": "_Test POS Setting",
"currency": "INR",
"conversion_rate": 1.0,
"price_list_name": "_Test Price List",
"company": "_Test Company",
"warehouse": "_Test Warehouse",
"cash_bank_account": "_Test Account Bank Account - _TC",
"income_account": "Sales - _TC",
"cost_center": "_Test Cost Center - _TC",
}]
]

View File

@@ -47,6 +47,7 @@ class DocType(SellingController):
def validate(self):
super(DocType, self).validate()
self.validate_posting_time()
self.so_dn_required()
self.validate_proj_cust()
sales_com_obj = get_obj('Sales Common')
@@ -636,10 +637,9 @@ class DocType(SellingController):
# Reduce actual qty from warehouse
self.make_sl_entry( d, d['warehouse'], - flt(d['qty']) , 0, update_stock)
get_obj('Stock Ledger', 'Stock Ledger').update_stock(self.values)
def get_actual_qty(self,args):
args = eval(args)
actual_qty = webnotes.conn.sql("select actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (args['item_code'], args['warehouse']), as_dict=1)

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-01-29 17:54:09",
"creation": "2013-03-12 11:56:25",
"docstatus": 0,
"modified": "2013-01-29 18:22:52",
"modified": "2013-03-12 14:31:24",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -77,7 +77,6 @@
"print_hide": 1
},
{
"default": "1",
"depends_on": "eval:doc.is_pos==1",
"doctype": "DocField",
"fieldname": "update_stock",

View File

@@ -297,7 +297,7 @@ class TestSalesInvoice(unittest.TestCase):
])
ps.insert()
test_dependencies = ["Journal Voucher"]
test_dependencies = ["Journal Voucher", "POS Setting"]
test_records = [
[

View File

@@ -63,12 +63,6 @@ wn.module_page["Accounts"] = [
"doctype": "Period Closing Voucher",
description: "Close Balance Sheet and book Profit or Loss."
},
{
"route":"Form/Sales and Purchase Return Tool/Sales and Purchase Return Tool",
"label": wn._("Sales and Purchase Return Tool"),
description: wn._("Manage sales or purchase returns"),
"doctype": "Sales and Purchase Return Tool"
},
{
"page":"voucher-import-tool",
"label": wn._("Voucher Import Tool"),