From 5d97d89a031492bc914c333a10472d7d4c3c274b Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 12 May 2016 12:58:29 +0530 Subject: [PATCH] [Fix] Sales Invoice shows default date while no default mentioned --- .../doctype/purchase_invoice/test_purchase_invoice.py | 5 ++--- .../accounts/doctype/sales_invoice/test_sales_invoice.py | 3 +-- erpnext/controllers/accounts_controller.py | 9 +++++---- erpnext/public/js/controllers/transaction.js | 8 -------- .../stock/doctype/delivery_note/test_delivery_note.py | 5 ++--- .../doctype/purchase_receipt/test_purchase_receipt.py | 7 ++++--- 6 files changed, 14 insertions(+), 23 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 91d3ae4dad..5dacb9babe 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import unittest import frappe import frappe.model -from frappe.utils import cint, flt +from frappe.utils import cint, flt, today import frappe.defaults from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory, \ test_records as pr_test_records @@ -412,8 +412,7 @@ class TestPurchaseInvoice(unittest.TestCase): def make_purchase_invoice(**args): pi = frappe.new_doc("Purchase Invoice") args = frappe._dict(args) - if args.posting_date: - pi.posting_date = args.posting_date + pi.posting_date = args.posting_date or today() if args.posting_time: pi.posting_time = args.posting_time if args.update_stock: diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 7208c2af74..abc4083f1c 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -955,8 +955,7 @@ class TestSalesInvoice(unittest.TestCase): def create_sales_invoice(**args): si = frappe.new_doc("Sales Invoice") args = frappe._dict(args) - if args.posting_date: - si.posting_date = args.posting_date or nowdate() + si.posting_date = args.posting_date or nowdate() si.company = args.company or "_Test Company" si.customer = args.customer or "_Test Customer" diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 2ede901ef3..e6d0ee900c 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -81,10 +81,11 @@ class AccountsController(TransactionBase): convert_to_recurring(self, self.get("posting_date") or self.get("transaction_date")) def set_missing_values(self, for_validate=False): - for fieldname in ["posting_date", "transaction_date"]: - if not self.get(fieldname) and self.meta.get_field(fieldname): - self.set(fieldname, today()) - break + if frappe.flags.in_test: + for fieldname in ["posting_date","transaction_date"]: + if self.meta.get_field(fieldname) and not self.get(fieldname): + self.set(fieldname, today()) + break def calculate_taxes_and_totals(self): from erpnext.controllers.taxes_and_totals import calculate_taxes_and_totals diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index af651c9b85..ac266f5418 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -87,15 +87,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ var today = get_today(), currency = frappe.defaults.get_user_default("currency"); - $.each(["posting_date", "transaction_date"], function(i, fieldname) { - if (me.frm.fields_dict[fieldname] && !me.frm.doc[fieldname] && me.frm[fieldname]) { - me.frm.set_value(fieldname, me.frm[fieldname]); - } - }); - $.each({ - posting_date: today, - transaction_date: today, currency: currency, price_list_currency: currency, status: "Draft", diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py index 699d8b6e2d..f10b981d73 100644 --- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py @@ -7,7 +7,7 @@ import unittest import frappe import json import frappe.defaults -from frappe.utils import cint, nowdate, nowtime, cstr, add_days, flt +from frappe.utils import cint, nowdate, nowtime, cstr, add_days, flt, today from erpnext.stock.stock_ledger import get_previous_sle from erpnext.accounts.utils import get_balance_on from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt \ @@ -516,8 +516,7 @@ class TestDeliveryNote(unittest.TestCase): def create_delivery_note(**args): dn = frappe.new_doc("Delivery Note") args = frappe._dict(args) - if args.posting_date: - dn.posting_date = args.posting_date + dn.posting_date = args.posting_date or today() if args.posting_time: dn.posting_time = args.posting_time diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index dc814056c8..eba9201cb4 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import unittest import frappe import frappe.defaults -from frappe.utils import cint, flt, cstr +from frappe.utils import cint, flt, cstr, today from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice class TestPurchaseReceipt(unittest.TestCase): @@ -193,6 +193,7 @@ class TestPurchaseReceipt(unittest.TestCase): po = create_purchase_order() pr1 = make_purchase_receipt(po.name) + pr1.posting_date = today() pr1.posting_time = "10:00" pr1.get("items")[0].received_qty = 2 pr1.get("items")[0].qty = 2 @@ -209,6 +210,7 @@ class TestPurchaseReceipt(unittest.TestCase): pi2.submit() pr2 = make_purchase_receipt(po.name) + pr2.posting_date = today() pr2.posting_time = "08:00" pr2.get("items")[0].received_qty = 5 pr2.get("items")[0].qty = 5 @@ -236,8 +238,7 @@ def set_perpetual_inventory(enable=1): def make_purchase_receipt(**args): pr = frappe.new_doc("Purchase Receipt") args = frappe._dict(args) - if args.posting_date: - pr.posting_date = args.posting_date + pr.posting_date = args.posting_date or today() if args.posting_time: pr.posting_time = args.posting_time pr.company = args.company or "_Test Company"