[fix] force stock_uom in item and stock ledger entry
This commit is contained in:
parent
ba9dbb1b09
commit
b16b9cd7a0
@ -11,6 +11,8 @@ from erpnext.utilities.transaction_base import TransactionBase
|
||||
from erpnext.controllers.recurring_document import convert_to_recurring, validate_recurring_document
|
||||
from erpnext.controllers.sales_and_purchase_return import validate_return
|
||||
|
||||
force_item_fields = ("item_name", "item_group", "barcode", "brand", "stock_uom")
|
||||
|
||||
class CustomerFrozen(frappe.ValidationError): pass
|
||||
|
||||
class AccountsController(TransactionBase):
|
||||
@ -18,12 +20,12 @@ class AccountsController(TransactionBase):
|
||||
if self.get("_action") and self._action != "update_after_submit":
|
||||
self.set_missing_values(for_validate=True)
|
||||
self.validate_date_with_fiscal_year()
|
||||
|
||||
|
||||
if self.meta.get_field("currency"):
|
||||
self.calculate_taxes_and_totals()
|
||||
if not self.meta.get_field("is_return") or not self.is_return:
|
||||
self.validate_value("base_grand_total", ">=", 0)
|
||||
|
||||
|
||||
validate_return(self)
|
||||
self.set_total_in_words()
|
||||
|
||||
@ -35,7 +37,7 @@ class AccountsController(TransactionBase):
|
||||
|
||||
if self.meta.get_field("taxes_and_charges"):
|
||||
self.validate_enabled_taxes_and_charges()
|
||||
|
||||
|
||||
self.validate_party()
|
||||
|
||||
def on_submit(self):
|
||||
@ -86,7 +88,7 @@ class AccountsController(TransactionBase):
|
||||
if self.doctype == "Sales Invoice":
|
||||
if not self.due_date:
|
||||
frappe.throw(_("Due Date is mandatory"))
|
||||
|
||||
|
||||
validate_due_date(self.posting_date, self.due_date, "Customer", self.customer, self.company)
|
||||
elif self.doctype == "Purchase Invoice":
|
||||
validate_due_date(self.posting_date, self.due_date, "Supplier", self.supplier, self.company)
|
||||
@ -142,7 +144,8 @@ class AccountsController(TransactionBase):
|
||||
|
||||
for fieldname, value in ret.items():
|
||||
if item.meta.get_field(fieldname) and \
|
||||
item.get(fieldname) is None and value is not None:
|
||||
(item.get(fieldname) is None or fieldname in force_item_fields) \
|
||||
and value is not None:
|
||||
item.set(fieldname, value)
|
||||
|
||||
if fieldname == "cost_center" and item.meta.get_field("cost_center") \
|
||||
@ -349,14 +352,14 @@ class AccountsController(TransactionBase):
|
||||
frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier')
|
||||
if frozen_accounts_modifier in frappe.get_roles():
|
||||
return
|
||||
|
||||
|
||||
party_type = None
|
||||
if self.meta.get_field("customer"):
|
||||
party_type = 'Customer'
|
||||
|
||||
elif self.meta.get_field("supplier"):
|
||||
party_type = 'Supplier'
|
||||
|
||||
|
||||
if party_type:
|
||||
party = self.get(party_type.lower())
|
||||
if frappe.db.get_value(party_type, party, "is_frozen"):
|
||||
|
@ -218,7 +218,7 @@ class StockController(AccountsController):
|
||||
tuple(item_codes))
|
||||
|
||||
return serialized_items
|
||||
|
||||
|
||||
def get_incoming_rate_for_sales_return(self, item_code, against_document):
|
||||
incoming_rate = 0.0
|
||||
if against_document and item_code:
|
||||
@ -229,12 +229,12 @@ class StockController(AccountsController):
|
||||
incoming_rate = incoming_rate[0][0] if incoming_rate else 0.0
|
||||
|
||||
return incoming_rate
|
||||
|
||||
|
||||
def update_reserved_qty(self, d):
|
||||
if d['reserved_qty'] < 0 :
|
||||
# Reduce reserved qty from reserved warehouse mentioned in so
|
||||
if not d["reserved_warehouse"]:
|
||||
frappe.throw(_("Reserved Warehouse is missing in Sales Order"))
|
||||
frappe.throw(_("Delivery Warehouse is missing in Sales Order"))
|
||||
|
||||
args = {
|
||||
"item_code": d['item_code'],
|
||||
|
@ -108,9 +108,13 @@ class Item(WebsiteGenerator):
|
||||
|
||||
def check_stock_uom_with_bin(self):
|
||||
if not self.get("__islocal"):
|
||||
if self.stock_uom == frappe.db.get_value("Item", self.name, "stock_uom"):
|
||||
return
|
||||
|
||||
matched=True
|
||||
ref_uom = frappe.db.get_value("Stock Ledger Entry",
|
||||
{"item_code": self.name}, "stock_uom")
|
||||
|
||||
if ref_uom:
|
||||
if cstr(ref_uom) != cstr(self.stock_uom):
|
||||
matched = False
|
||||
@ -128,7 +132,7 @@ class Item(WebsiteGenerator):
|
||||
(self.stock_uom, self.name))
|
||||
|
||||
if not matched:
|
||||
frappe.throw(_("Default Unit of Measure can not be changed directly because you have already made some transaction(s) with another UOM. To change default UOM, use 'UOM Replace Utility' tool under Stock module."))
|
||||
frappe.throw(_("Default Unit of Measure for Item {0} cannot be changed directly because you have already made some transaction(s) with another UOM. To change default UOM, use 'UOM Replace Utility' tool under Stock module.").format(self.name))
|
||||
|
||||
def update_template_tables(self):
|
||||
template = frappe.get_doc("Item", self.variant_of)
|
||||
|
@ -82,8 +82,7 @@ class StockLedgerEntry(Document):
|
||||
frappe.throw(_("Stock cannot exist for Item {0} since has variants").format(self.item_code),
|
||||
ItemTemplateCannotHaveStock)
|
||||
|
||||
if not self.stock_uom:
|
||||
self.stock_uom = item_det.stock_uom
|
||||
self.stock_uom = item_det.stock_uom
|
||||
|
||||
def check_stock_frozen_date(self):
|
||||
stock_frozen_upto = frappe.db.get_value('Stock Settings', None, 'stock_frozen_upto') or ''
|
||||
|
Loading…
Reference in New Issue
Block a user