fix: Changed check condition and added test
This commit is contained in:
parent
236140d94c
commit
214acc9a42
@ -536,7 +536,7 @@ frappe.ui.form.on('Stock Entry Detail', {
|
||||
if(r.message) {
|
||||
var d = locals[cdt][cdn];
|
||||
$.each(r.message, function(k, v) {
|
||||
d[k] = v;
|
||||
frappe.model.set_value(cdt, cdn, k, v); // qty and it's subsequent fields weren't triggered
|
||||
});
|
||||
refresh_field("items");
|
||||
erpnext.stock.select_batch_and_serial_no(frm, d);
|
||||
|
@ -27,6 +27,7 @@ class IncorrectValuationRateError(frappe.ValidationError): pass
|
||||
class DuplicateEntryForWorkOrderError(frappe.ValidationError): pass
|
||||
class OperationsNotCompleteError(frappe.ValidationError): pass
|
||||
class MaxSampleAlreadyRetainedError(frappe.ValidationError): pass
|
||||
class TotalBasicAmountZeroError(frappe.ValidationError): pass
|
||||
|
||||
from erpnext.controllers.stock_controller import StockController
|
||||
|
||||
@ -649,6 +650,12 @@ class StockEntry(StockController):
|
||||
gl_entries = super(StockEntry, self).get_gl_entries(warehouse_account)
|
||||
|
||||
total_basic_amount = sum([flt(t.basic_amount) for t in self.get("items") if t.t_warehouse])
|
||||
|
||||
if self.get("additional_costs") and not total_basic_amount:
|
||||
#If additional costs table is populated and total basic amount is
|
||||
#somehow 0, interrupt transaction.
|
||||
frappe.throw(_("Total Basic Amount in Items Table cannot be 0"), TotalBasicAmountZeroError)
|
||||
|
||||
item_account_wise_additional_cost = {}
|
||||
|
||||
for t in self.get("additional_costs"):
|
||||
@ -657,7 +664,7 @@ class StockEntry(StockController):
|
||||
item_account_wise_additional_cost.setdefault((d.item_code, d.name), {})
|
||||
item_account_wise_additional_cost[(d.item_code, d.name)].setdefault(t.expense_account, 0.0)
|
||||
item_account_wise_additional_cost[(d.item_code, d.name)][t.expense_account] += \
|
||||
(t.amount * d.basic_amount) / total_basic_amount if total_basic_amount else 0
|
||||
(t.amount * d.basic_amount) / total_basic_amount
|
||||
|
||||
if item_account_wise_additional_cost:
|
||||
for d in self.get("items"):
|
||||
|
@ -16,6 +16,7 @@ from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
||||
from erpnext.accounts.doctype.account.test_account import get_inventory_account
|
||||
from erpnext.stock.doctype.stock_entry.stock_entry import move_sample_to_retention_warehouse, make_stock_in_entry
|
||||
from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import OpeningEntryAccountError
|
||||
from erpnext.stock.doctype.stock_entry.stock_entry import TotalBasicAmountZeroError
|
||||
from six import iteritems
|
||||
|
||||
def get_sle(**args):
|
||||
@ -790,6 +791,32 @@ class TestStockEntry(unittest.TestCase):
|
||||
filters={"voucher_type": "Stock Entry", "voucher_no": mr.name}, fieldname="is_opening")
|
||||
self.assertEqual(is_opening, "Yes")
|
||||
|
||||
def test_total_basic_amount_zero(self):
|
||||
se = frappe.get_doc({"doctype":"Stock Entry",
|
||||
"purpose":"Material Receipt",
|
||||
"stock_entry_type":"Material Receipt",
|
||||
"posting_date": nowdate(),
|
||||
"company":"_Test Company with perpetual inventory",
|
||||
"items":[
|
||||
{"item_code":"Basil Leaves",
|
||||
"description":"Basil Leaves",
|
||||
"qty": 1,
|
||||
"basic_rate": 0,
|
||||
"uom":"Nos",
|
||||
"t_warehouse": "Stores - TCP1",
|
||||
"allow_zero_valuation_rate": 1,
|
||||
"cost_center": "Main - TCP1"}
|
||||
],
|
||||
"additional_costs":[
|
||||
{"expense_account":"Miscellaneous Expenses - TCP1",
|
||||
"amount":100,
|
||||
"description": "miscellanous"}
|
||||
]
|
||||
})
|
||||
|
||||
se.insert()
|
||||
self.assertRaises(TotalBasicAmountZeroError, se.submit)
|
||||
|
||||
def make_serialized_item(item_code=None, serial_no=None, target_warehouse=None):
|
||||
se = frappe.copy_doc(test_records[0])
|
||||
se.get("items")[0].item_code = item_code or "_Test Serialized Item With Series"
|
||||
|
Loading…
x
Reference in New Issue
Block a user