Merge pull request #24985 from ankush/allow_zero_valuation_SR_v13b_pr

fix: Allow zero valuation in stock reconciliation
This commit is contained in:
Marica 2021-03-23 14:58:38 +05:30 committed by GitHub
commit 5c7138c86b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 4 deletions

View File

@ -29,6 +29,8 @@ class StockReconciliation(StockController):
self.remove_items_with_no_change()
self.validate_data()
self.validate_expense_account()
self.validate_customer_provided_item()
self.set_zero_value_for_customer_provided_items()
self.set_total_qty_and_amount()
self.validate_putaway_capacity()
@ -217,7 +219,7 @@ class StockReconciliation(StockController):
if row.valuation_rate in ("", None):
row.valuation_rate = previous_sle.get("valuation_rate", 0)
if row.qty and not row.valuation_rate:
if row.qty and not row.valuation_rate and not row.allow_zero_valuation_rate:
frappe.throw(_("Valuation Rate required for Item {0} at row {1}").format(row.item_code, row.idx))
if ((previous_sle and row.qty == previous_sle.get("qty_after_transaction")
@ -436,6 +438,20 @@ class StockReconciliation(StockController):
if frappe.db.get_value("Account", self.expense_account, "report_type") == "Profit and Loss":
frappe.throw(_("Difference Account must be a Asset/Liability type account, since this Stock Reconciliation is an Opening Entry"), OpeningEntryAccountError)
def set_zero_value_for_customer_provided_items(self):
changed_any_values = False
for d in self.get('items'):
is_customer_item = frappe.db.get_value('Item', d.item_code, 'is_customer_provided_item')
if is_customer_item and d.valuation_rate:
d.valuation_rate = 0.0
changed_any_values = True
if changed_any_values:
msgprint(_("Valuation rate for customer provided items has been set to zero."),
title=_("Note"), indicator="blue")
def set_total_qty_and_amount(self):
for d in self.get("items"):
d.amount = flt(d.qty, d.precision("qty")) * flt(d.valuation_rate, d.precision("valuation_rate"))
@ -531,4 +547,4 @@ def get_difference_account(purpose, company):
account = frappe.db.get_value('Account', {'is_group': 0,
'company': company, 'account_type': 'Temporary'}, 'name')
return account
return account

View File

@ -193,6 +193,16 @@ class TestStockReconciliation(unittest.TestCase):
stock_doc = frappe.get_doc("Stock Reconciliation", d)
stock_doc.cancel()
def test_customer_provided_items(self):
item_code = 'Stock-Reco-customer-Item-100'
create_item(item_code, is_customer_provided_item = 1,
customer = '_Test Customer', is_purchase_item = 0)
sr = create_stock_reconciliation(item_code = item_code, qty = 10, rate = 420)
self.assertEqual(sr.get("items")[0].allow_zero_valuation_rate, 1)
self.assertEqual(sr.get("items")[0].valuation_rate, 0)
self.assertEqual(sr.get("items")[0].amount, 0)
def insert_existing_sle(warehouse):
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry

View File

@ -13,6 +13,7 @@
"qty",
"valuation_rate",
"amount",
"allow_zero_valuation_rate",
"serial_no_and_batch_section",
"serial_no",
"column_break_11",
@ -166,10 +167,19 @@
"fieldtype": "Link",
"label": "Batch No",
"options": "Batch"
},
{
"default": "0",
"fieldname": "allow_zero_valuation_rate",
"fieldtype": "Check",
"label": "Allow Zero Valuation Rate",
"print_hide": 1,
"read_only": 1
}
],
"istable": 1,
"modified": "2019-06-14 17:10:53.188305",
"links": [],
"modified": "2021-03-23 11:09:44.407157",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Reconciliation Item",
@ -179,4 +189,4 @@
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}
}