[fixes] test cases, code cleanup.

This commit is contained in:
Saurabh 2016-03-21 18:32:48 +05:30 committed by Nabin Hait
parent 2a0e2fe95c
commit 43520f93a1
7 changed files with 120 additions and 96 deletions

View File

@ -111,7 +111,6 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
cur_frm.cscript.hide_fields(this.frm.doc); cur_frm.cscript.hide_fields(this.frm.doc);
if(cint(this.frm.doc.is_paid)) { if(cint(this.frm.doc.is_paid)) {
if(!this.frm.doc.company) { if(!this.frm.doc.company) {
this.frm.set_value("x", 0);
msgprint(__("Please specify Company to proceed")); msgprint(__("Please specify Company to proceed"));
} }
} }
@ -165,22 +164,21 @@ cur_frm.script_manager.make(erpnext.accounts.PurchaseInvoice);
// Hide Fields // Hide Fields
// ------------ // ------------
cur_frm.cscript.hide_fields = function(doc) { cur_frm.cscript.hide_fields = function(doc) {
par_flds = ['due_date', 'is_opening', 'advances_section', 'from_date', 'to_date']; parent_fields = ['due_date', 'is_opening', 'advances_section', 'from_date', 'to_date'];
if(cint(doc.is_paid) == 1) { if(cint(doc.is_paid) == 1) {
hide_field(par_flds); hide_field(parent_fields);
} else { } else {
for (i in par_flds) { for (i in parent_fields) {
var docfield = frappe.meta.docfield_map[doc.doctype][par_flds[i]]; var docfield = frappe.meta.docfield_map[doc.doctype][parent_fields[i]];
if(!docfield.hidden) unhide_field(par_flds[i]); if(!docfield.hidden) unhide_field(parent_fields[i]);
} }
} }
item_flds_stock = ['warehouse_section', 'received_qty', 'rejected_qty']; item_fields_stock = ['warehouse_section', 'received_qty', 'rejected_qty'];
//item_flds_stock = ['serial_no', 'batch_no', 'actual_qty', 'expense_account', 'warehouse', 'expense_account', 'warehouse'] cur_frm.fields_dict['items'].grid.set_column_disp(item_fields_stock,
cur_frm.fields_dict['items'].grid.set_column_disp(item_flds_stock,
(cint(doc.update_stock)==1 ? true : false)); (cint(doc.update_stock)==1 ? true : false));
cur_frm.refresh_fields(); cur_frm.refresh_fields();
@ -190,24 +188,6 @@ cur_frm.cscript.update_stock = function(doc, dt, dn) {
cur_frm.cscript.hide_fields(doc, dt, dn); cur_frm.cscript.hide_fields(doc, dt, dn);
} }
cur_frm.cscript.mode_of_payment = function(doc) {
if(doc.is_paid) {
return cur_frm.call({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
args: {
"mode_of_payment": doc.mode_of_payment,
"company": doc.company
},
callback: function(r, rt) {
if(r.message) {
cur_frm.set_value("cash_bank_account", r.message["account"]);
}
}
});
}
}
cur_frm.fields_dict.cash_bank_account.get_query = function(doc) { cur_frm.fields_dict.cash_bank_account.get_query = function(doc) {
return { return {
filters: [ filters: [

View File

@ -116,6 +116,31 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "is_paid",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Is Paid",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
@ -277,14 +302,14 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"default": "0", "default": "0",
"fieldname": "is_paid", "fieldname": "is_return",
"fieldtype": "Check", "fieldtype": "Check",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Is Paid", "label": "Is Return",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
@ -2624,7 +2649,34 @@
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name",
"description": "",
"fieldname": "notify_by_email",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Notify by email",
"length": 0,
"no_copy": 1,
"permlevel": 0,
"precision": "",
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 1, "allow_on_submit": 1,
"bold": 0, "bold": 0,

View File

@ -354,7 +354,7 @@ class PurchaseInvoice(BuyingController):
# self.bk_flush_supp_wh(sl_entries) # self.bk_flush_supp_wh(sl_entries)
self.make_sl_entries(sl_entries, allow_negative_stock=allow_negative_stock, self.make_sl_entries(sl_entries, allow_negative_stock=allow_negative_stock,
via_landed_cost_voucher=via_landed_cost_voucher) via_landed_cost_voucher=via_landed_cost_voucher)
def on_submit(self): def on_submit(self):
self.check_prev_docstatus() self.check_prev_docstatus()
self.validate_asset() self.validate_asset()
@ -381,7 +381,6 @@ class PurchaseInvoice(BuyingController):
self.update_billing_status_in_pr() self.update_billing_status_in_pr()
self.update_project() self.update_project()
<<<<<<< 1b49ed56bdbd4a6cdf93ede3bfa252e5a954ed41
def validate_asset(self): def validate_asset(self):
for d in self.get("items"): for d in self.get("items"):
@ -409,23 +408,7 @@ class PurchaseInvoice(BuyingController):
if self.docstatus==1 and not asset.supplier: if self.docstatus==1 and not asset.supplier:
frappe.db.set_value("Asset", asset.name, "supplier", self.supplier) frappe.db.set_value("Asset", asset.name, "supplier", self.supplier)
=======
def on_cancel(self):
if not self.is_return:
from erpnext.accounts.utils import remove_against_link_from_jv
remove_against_link_from_jv(self.doctype, self.name)
self.update_prevdoc_status()
self.update_billing_status_for_zero_amount_refdoc("Purchase Order")
self.update_billing_status_in_pr()
self.update_stock_ledger()
self.make_gl_entries_on_cancel()
self.update_project()
>>>>>>> [fixes] fix perpetual inventory
def make_gl_entries(self): def make_gl_entries(self):
auto_accounting_for_stock = \ auto_accounting_for_stock = \
cint(frappe.defaults.get_global_default("auto_accounting_for_stock")) cint(frappe.defaults.get_global_default("auto_accounting_for_stock"))

View File

@ -315,12 +315,7 @@ class TestPurchaseInvoice(unittest.TestCase):
self.assertFalse(gle) self.assertFalse(gle)
def purchase_invoice_gl_entry_with_perpetual_inventory(self): def test_purchase_invoice_update_stock_gl_entry_with_perpetual_inventory(self):
"""
1. create purchase invoice with update stock as true
2. get gl entry against purchase invoice
3. check accounts
"""
set_perpetual_inventory() set_perpetual_inventory()
pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(), pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(),
posting_time=frappe.utils.nowtime()) posting_time=frappe.utils.nowtime())
@ -334,7 +329,30 @@ class TestPurchaseInvoice(unittest.TestCase):
expected_gl_entries = dict((d[0], d) for d in [ expected_gl_entries = dict((d[0], d) for d in [
[pi.credit_to, 0.0, 250.0], [pi.credit_to, 0.0, 250.0],
[pi.get("items")[0]["warehouse"], 250.0, 0.0] [pi.items[0].warehouse, 250.0, 0.0]
])
for i, gle in enumerate(gl_entries):
self.assertEquals(expected_gl_entries[gle.account][0], gle.account)
self.assertEquals(expected_gl_entries[gle.account][1], gle.debit)
self.assertEquals(expected_gl_entries[gle.account][2], gle.credit)
def test_purchase_invoice_for_is_paid_and_update_stock_gl_entry_with_perpetual_inventory(self):
set_perpetual_inventory()
pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(),
posting_time=frappe.utils.nowtime(), cash_bank_account="Cash - _TC", is_paid=1)
gl_entries = frappe.db.sql("""select account, account_currency, debit, credit,
debit_in_account_currency, credit_in_account_currency
from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
order by account asc""", pi.name, as_dict=1)
self.assertTrue(gl_entries)
expected_gl_entries = dict((d[0], d) for d in [
[pi.credit_to, 250, 250.0],
[pi.items[0].warehouse, 250.0, 0.0],
["Cash - _TC", 0.0, 250.0]
]) ])
for i, gle in enumerate(gl_entries): for i, gle in enumerate(gl_entries):
@ -351,6 +369,11 @@ def make_purchase_invoice(**args):
pi.posting_time = args.posting_time pi.posting_time = args.posting_time
if args.update_stock: if args.update_stock:
pi.update_stock = 1 pi.update_stock = 1
if args.is_paid:
pi.is_paid = 1
if args.cash_bank_account:
pi.cash_bank_account=args.cash_bank_account
pi.company = args.company or "_Test Company" pi.company = args.company or "_Test Company"
pi.supplier = args.supplier or "_Test Supplier" pi.supplier = args.supplier or "_Test Supplier"
pi.currency = args.currency or "INR" pi.currency = args.currency or "INR"

View File

@ -278,20 +278,20 @@ $.extend(cur_frm.cscript, new erpnext.accounts.SalesInvoiceController({frm: cur_
// Hide Fields // Hide Fields
// ------------ // ------------
cur_frm.cscript.hide_fields = function(doc) { cur_frm.cscript.hide_fields = function(doc) {
par_flds = ['project', 'due_date', 'is_opening', 'source', 'total_advance', 'get_advances_received', parent_fields = ['project', 'due_date', 'is_opening', 'source', 'total_advance', 'get_advances_received',
'advances', 'sales_partner', 'commission_rate', 'total_commission', 'advances', 'from_date', 'to_date']; 'advances', 'sales_partner', 'commission_rate', 'total_commission', 'advances', 'from_date', 'to_date'];
if(cint(doc.is_pos) == 1) { if(cint(doc.is_pos) == 1) {
hide_field(par_flds); hide_field(parent_fields);
} else { } else {
for (i in par_flds) { for (i in parent_fields) {
var docfield = frappe.meta.docfield_map[doc.doctype][par_flds[i]]; var docfield = frappe.meta.docfield_map[doc.doctype][parent_fields[i]];
if(!docfield.hidden) unhide_field(par_flds[i]); if(!docfield.hidden) unhide_field(parent_fields[i]);
} }
} }
item_flds_stock = ['serial_no', 'batch_no', 'actual_qty', 'expense_account', 'warehouse', 'expense_account', 'warehouse'] item_fields_stock = ['serial_no', 'batch_no', 'actual_qty', 'expense_account', 'warehouse', 'expense_account', 'warehouse']
cur_frm.fields_dict['items'].grid.set_column_disp(item_flds_stock, cur_frm.fields_dict['items'].grid.set_column_disp(item_fields_stock,
(cint(doc.update_stock)==1 ? true : false)); (cint(doc.update_stock)==1 ? true : false));
// India related fields // India related fields
@ -303,25 +303,6 @@ cur_frm.cscript.hide_fields = function(doc) {
cur_frm.refresh_fields(); cur_frm.refresh_fields();
} }
cur_frm.cscript.mode_of_payment = function(doc) {
if(doc.is_pos) {
return cur_frm.call({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
args: {
"mode_of_payment": doc.mode_of_payment,
"company": doc.company
},
callback: function(r, rt) {
if(r.message) {
cur_frm.set_value("cash_bank_account", r.message["account"]);
}
}
});
}
}
cur_frm.cscript.update_stock = function(doc, dt, dn) { cur_frm.cscript.update_stock = function(doc, dt, dn) {
cur_frm.cscript.hide_fields(doc, dt, dn); cur_frm.cscript.hide_fields(doc, dt, dn);
} }

View File

@ -461,21 +461,6 @@ class SalesInvoice(SellingController):
d.income_account = disposal_account d.income_account = disposal_account
def on_update(self):
if cint(self.is_pos) == 1:
if flt(self.paid_amount) == 0:
if self.cash_bank_account:
frappe.db.set(self, 'paid_amount',
flt(flt(self.grand_total) - flt(self.write_off_amount), self.precision("paid_amount")))
else:
# show message that the amount is not paid
frappe.db.set(self,'paid_amount',0)
frappe.msgprint(_("Note: Payment Entry will not be created since 'Cash or Bank Account' was not specified"))
else:
frappe.db.set(self,'paid_amount',0)
frappe.db.set(self, 'base_paid_amount',
flt(self.paid_amount*self.conversion_rate, self.precision("base_paid_amount")))
def check_prev_docstatus(self): def check_prev_docstatus(self):
for d in self.get('items'): for d in self.get('items'):

View File

@ -54,6 +54,26 @@ class AccountsController(TransactionBase):
if not self.get("__islocal"): if not self.get("__islocal"):
validate_recurring_document(self) validate_recurring_document(self)
convert_to_recurring(self, self.get("posting_date") or self.get("transaction_date")) convert_to_recurring(self, self.get("posting_date") or self.get("transaction_date"))
self.validate_paid_amount()
def validate_paid_amount(self):
if hasattr(self, "is_pos") or hasattr(self, "is_paid"):
is_paid = self.get("is_pos") or self.get("is_paid")
if cint(is_paid) == 1:
if flt(self.paid_amount) == 0:
if self.cash_bank_account:
frappe.db.set(self, 'paid_amount',
flt(flt(self.grand_total) - flt(self.write_off_amount), self.precision("paid_amount")))
else:
# show message that the amount is not paid
frappe.db.set(self,'paid_amount',0)
frappe.msgprint(_("Note: Payment Entry will not be created since 'Cash or Bank Account' was not specified"))
else:
frappe.db.set(self,'paid_amount',0)
frappe.db.set(self, 'base_paid_amount',
flt(self.paid_amount*self.conversion_rate, self.precision("base_paid_amount")))
def on_update_after_submit(self): def on_update_after_submit(self):
if self.meta.get_field("is_recurring"): if self.meta.get_field("is_recurring"):