mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-21 07:38:29 +00:00
* fix: custom stock entry type issue (#42835)
(cherry picked from commit 9c82c2b5d3)
# Conflicts:
# erpnext/stock/doctype/stock_entry_type/stock_entry_type.py
* chore: fix conflicts
* chore: fix linters issue
---------
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -372,3 +372,4 @@ erpnext.patches.v15_0.update_asset_repair_field_in_stock_entry
|
|||||||
erpnext.patches.v15_0.update_total_number_of_booked_depreciations
|
erpnext.patches.v15_0.update_total_number_of_booked_depreciations
|
||||||
erpnext.patches.v15_0.do_not_use_batchwise_valuation
|
erpnext.patches.v15_0.do_not_use_batchwise_valuation
|
||||||
erpnext.patches.v15_0.drop_index_posting_datetime_from_sle
|
erpnext.patches.v15_0.drop_index_posting_datetime_from_sle
|
||||||
|
erpnext.patches.v15_0.set_standard_stock_entry_type
|
||||||
|
|||||||
16
erpnext/patches/v15_0/set_standard_stock_entry_type.py
Normal file
16
erpnext/patches/v15_0/set_standard_stock_entry_type.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import frappe
|
||||||
|
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
for stock_entry_type in [
|
||||||
|
"Material Issue",
|
||||||
|
"Material Receipt",
|
||||||
|
"Material Transfer",
|
||||||
|
"Material Transfer for Manufacture",
|
||||||
|
"Material Consumption for Manufacture",
|
||||||
|
"Manufacture",
|
||||||
|
"Repack",
|
||||||
|
"Send to Subcontractor",
|
||||||
|
]:
|
||||||
|
if frappe.db.exists("Stock Entry Type", stock_entry_type):
|
||||||
|
frappe.db.set_value("Stock Entry Type", stock_entry_type, "is_standard", 1)
|
||||||
@@ -66,29 +66,53 @@ def install(country=None):
|
|||||||
"parent_item_group": _("All Item Groups"),
|
"parent_item_group": _("All Item Groups"),
|
||||||
},
|
},
|
||||||
# Stock Entry Type
|
# Stock Entry Type
|
||||||
{"doctype": "Stock Entry Type", "name": "Material Issue", "purpose": "Material Issue"},
|
{
|
||||||
{"doctype": "Stock Entry Type", "name": "Material Receipt", "purpose": "Material Receipt"},
|
"doctype": "Stock Entry Type",
|
||||||
|
"name": "Material Issue",
|
||||||
|
"purpose": "Material Issue",
|
||||||
|
"is_standard": 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Stock Entry Type",
|
||||||
|
"name": "Material Receipt",
|
||||||
|
"purpose": "Material Receipt",
|
||||||
|
"is_standard": 1,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Stock Entry Type",
|
"doctype": "Stock Entry Type",
|
||||||
"name": "Material Transfer",
|
"name": "Material Transfer",
|
||||||
"purpose": "Material Transfer",
|
"purpose": "Material Transfer",
|
||||||
|
"is_standard": 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Stock Entry Type",
|
||||||
|
"name": "Manufacture",
|
||||||
|
"purpose": "Manufacture",
|
||||||
|
"is_standard": 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Stock Entry Type",
|
||||||
|
"name": "Repack",
|
||||||
|
"purpose": "Repack",
|
||||||
|
"is_standard": 1,
|
||||||
},
|
},
|
||||||
{"doctype": "Stock Entry Type", "name": "Manufacture", "purpose": "Manufacture"},
|
|
||||||
{"doctype": "Stock Entry Type", "name": "Repack", "purpose": "Repack"},
|
|
||||||
{
|
{
|
||||||
"doctype": "Stock Entry Type",
|
"doctype": "Stock Entry Type",
|
||||||
"name": "Send to Subcontractor",
|
"name": "Send to Subcontractor",
|
||||||
"purpose": "Send to Subcontractor",
|
"purpose": "Send to Subcontractor",
|
||||||
|
"is_standard": 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Stock Entry Type",
|
"doctype": "Stock Entry Type",
|
||||||
"name": "Material Transfer for Manufacture",
|
"name": "Material Transfer for Manufacture",
|
||||||
"purpose": "Material Transfer for Manufacture",
|
"purpose": "Material Transfer for Manufacture",
|
||||||
|
"is_standard": 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Stock Entry Type",
|
"doctype": "Stock Entry Type",
|
||||||
"name": "Material Consumption for Manufacture",
|
"name": "Material Consumption for Manufacture",
|
||||||
"purpose": "Material Consumption for Manufacture",
|
"purpose": "Material Consumption for Manufacture",
|
||||||
|
"is_standard": 1,
|
||||||
},
|
},
|
||||||
# territory: with two default territories, one for home country and one named Rest of the World
|
# territory: with two default territories, one for home country and one named Rest of the World
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -983,7 +983,7 @@ class StockEntry(StockController):
|
|||||||
def set_stock_entry_type(self):
|
def set_stock_entry_type(self):
|
||||||
if self.purpose:
|
if self.purpose:
|
||||||
self.stock_entry_type = frappe.get_cached_value(
|
self.stock_entry_type = frappe.get_cached_value(
|
||||||
"Stock Entry Type", {"purpose": self.purpose}, "name"
|
"Stock Entry Type", {"purpose": self.purpose, "is_standard": 1}, "name"
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_purpose_for_stock_entry(self):
|
def set_purpose_for_stock_entry(self):
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"purpose",
|
"purpose",
|
||||||
"add_to_transit"
|
"add_to_transit",
|
||||||
|
"is_standard"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -26,10 +27,17 @@
|
|||||||
"fieldname": "add_to_transit",
|
"fieldname": "add_to_transit",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Add to Transit"
|
"label": "Add to Transit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "is_standard",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Is Standard",
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-07-08 08:41:19.385020",
|
"modified": "2024-08-20 15:35:45.696958",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Stock Entry Type",
|
"name": "Stock Entry Type",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
|
||||||
# import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@ class StockEntryType(Document):
|
|||||||
from frappe.types import DF
|
from frappe.types import DF
|
||||||
|
|
||||||
add_to_transit: DF.Check
|
add_to_transit: DF.Check
|
||||||
|
is_standard: DF.Check
|
||||||
purpose: DF.Literal[
|
purpose: DF.Literal[
|
||||||
"",
|
"",
|
||||||
"Material Issue",
|
"Material Issue",
|
||||||
@@ -30,5 +31,19 @@ class StockEntryType(Document):
|
|||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
self.validate_standard_type()
|
||||||
if self.add_to_transit and self.purpose != "Material Transfer":
|
if self.add_to_transit and self.purpose != "Material Transfer":
|
||||||
self.add_to_transit = 0
|
self.add_to_transit = 0
|
||||||
|
|
||||||
|
def validate_standard_type(self):
|
||||||
|
if self.is_standard and self.name not in [
|
||||||
|
"Material Issue",
|
||||||
|
"Material Receipt",
|
||||||
|
"Material Transfer",
|
||||||
|
"Material Transfer for Manufacture",
|
||||||
|
"Material Consumption for Manufacture",
|
||||||
|
"Manufacture",
|
||||||
|
"Repack",
|
||||||
|
"Send to Subcontractor",
|
||||||
|
]:
|
||||||
|
frappe.throw(f"Stock Entry Type {self.name} cannot be set as standard")
|
||||||
|
|||||||
@@ -3,6 +3,33 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
|
||||||
|
|
||||||
class TestStockEntryType(unittest.TestCase):
|
class TestStockEntryType(unittest.TestCase):
|
||||||
pass
|
def test_stock_entry_type_non_standard(self):
|
||||||
|
stock_entry_type = "Test Manufacturing"
|
||||||
|
|
||||||
|
doc = frappe.get_doc(
|
||||||
|
{
|
||||||
|
"doctype": "Stock Entry Type",
|
||||||
|
"__newname": stock_entry_type,
|
||||||
|
"purpose": "Manufacture",
|
||||||
|
"is_standard": 1,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertRaises(frappe.ValidationError, doc.insert)
|
||||||
|
|
||||||
|
def test_stock_entry_type_is_standard(self):
|
||||||
|
for stock_entry_type in [
|
||||||
|
"Material Issue",
|
||||||
|
"Material Receipt",
|
||||||
|
"Material Transfer",
|
||||||
|
"Material Transfer for Manufacture",
|
||||||
|
"Material Consumption for Manufacture",
|
||||||
|
"Manufacture",
|
||||||
|
"Repack",
|
||||||
|
"Send to Subcontractor",
|
||||||
|
]:
|
||||||
|
self.assertTrue(frappe.db.get_value("Stock Entry Type", stock_entry_type, "is_standard"))
|
||||||
|
|||||||
Reference in New Issue
Block a user