From a645f36b2ba2c5ceb170cc68d448e30a19a55c4b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 1 Mar 2018 10:31:24 +0530 Subject: [PATCH] Get valuation rate from historical SLE even if it is zero (#13129) * Don't overwrite start and end date comes from payroll entry * Get valuation rate from historical SLE even if it is zero, if records exists * Valid till should be autoset if not any default value * Set status of expense claim based on is_paid check --- .../hr/doctype/expense_claim/expense_claim.py | 7 +++--- erpnext/hr/doctype/salary_slip/salary_slip.py | 7 +++--- .../selling/doctype/quotation/quotation.js | 2 +- erpnext/stock/stock_ledger.py | 24 +++++++++---------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py index 9462211c09..d0c4a46e3e 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -45,10 +45,11 @@ class ExpenseClaim(AccountsController): }[cstr(self.docstatus or 0)] paid_amount = flt(self.total_amount_reimbursed) + flt(self.total_advance_amount) - if self.total_sanctioned_amount > 0 and self.total_sanctioned_amount == paid_amount\ + if (self.is_paid or (flt(self.total_sanctioned_amount) > 0 + and flt(self.total_sanctioned_amount) == paid_amount)) \ and self.docstatus == 1 and self.approval_status == 'Approved': - self.status = "Paid" - elif self.total_sanctioned_amount > 0 and self.docstatus == 1 and self.approval_status == 'Approved': + self.status = "Paid" + elif flt(self.total_sanctioned_amount) > 0 and self.docstatus == 1 and self.approval_status == 'Approved': self.status = "Unpaid" elif self.docstatus == 1 and self.approval_status == 'Rejected': self.status = 'Rejected' diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py index a474569603..b9371e31fb 100644 --- a/erpnext/hr/doctype/salary_slip/salary_slip.py +++ b/erpnext/hr/doctype/salary_slip/salary_slip.py @@ -156,9 +156,10 @@ class SalarySlip(TransactionBase): }) def get_date_details(self): - date_details = get_start_end_dates(self.payroll_frequency, self.start_date or self.posting_date) - self.start_date = date_details.start_date - self.end_date = date_details.end_date + if not self.end_date: + date_details = get_start_end_dates(self.payroll_frequency, self.start_date or self.posting_date) + self.start_date = date_details.start_date + self.end_date = date_details.end_date def check_sal_struct(self, joining_date, relieving_date): cond = '' diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 84176426be..081d4dbe9a 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -41,7 +41,7 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ var me = this; - if (doc.__islocal) { + if (doc.__islocal && !doc.valid_till) { this.frm.set_value('valid_till', frappe.datetime.add_months(doc.transaction_date, 1)) } diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 874a382192..db9c2a682f 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -452,22 +452,22 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, where item_code = %s and valuation_rate > 0 order by posting_date desc, posting_time desc, name desc limit 1""", item_code) - valuation_rate = flt(last_valuation_rate[0][0]) if last_valuation_rate else 0 + if last_valuation_rate: + return flt(last_valuation_rate[0][0]) # as there is previous records, it might come with zero rate + + # If negative stock allowed, and item delivered without any incoming entry, + # system does not found any SLE, then take valuation rate from Item + valuation_rate = frappe.db.get_value("Item", item_code, "valuation_rate") if not valuation_rate: - # If negative stock allowed, and item delivered without any incoming entry, - # syste does not found any SLE, then take valuation rate from Item - valuation_rate = frappe.db.get_value("Item", item_code, "valuation_rate") + # try Item Standard rate + valuation_rate = frappe.db.get_value("Item", item_code, "standard_rate") if not valuation_rate: - # try Item Standard rate - valuation_rate = frappe.db.get_value("Item", item_code, "standard_rate") - - if not valuation_rate: - # try in price list - valuation_rate = frappe.db.get_value('Item Price', - dict(item_code=item_code, buying=1, currency=currency), - 'price_list_rate') + # try in price list + valuation_rate = frappe.db.get_value('Item Price', + dict(item_code=item_code, buying=1, currency=currency), + 'price_list_rate') if not allow_zero_rate and not valuation_rate \ and cint(erpnext.is_perpetual_inventory_enabled(company)):