mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 00:44:45 +00:00
Merge branch 'develop' into FIX-34354
This commit is contained in:
@@ -31,7 +31,7 @@ class BOMTree:
|
|||||||
|
|
||||||
# specifying the attributes to save resources
|
# specifying the attributes to save resources
|
||||||
# ref: https://docs.python.org/3/reference/datamodel.html#slots
|
# ref: https://docs.python.org/3/reference/datamodel.html#slots
|
||||||
__slots__ = ["name", "child_items", "is_bom", "item_code", "exploded_qty", "qty"]
|
__slots__ = ["name", "child_items", "is_bom", "item_code", "qty", "exploded_qty", "bom_qty"]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, name: str, is_bom: bool = True, exploded_qty: float = 1.0, qty: float = 1
|
self, name: str, is_bom: bool = True, exploded_qty: float = 1.0, qty: float = 1
|
||||||
@@ -50,9 +50,10 @@ class BOMTree:
|
|||||||
def __create_tree(self):
|
def __create_tree(self):
|
||||||
bom = frappe.get_cached_doc("BOM", self.name)
|
bom = frappe.get_cached_doc("BOM", self.name)
|
||||||
self.item_code = bom.item
|
self.item_code = bom.item
|
||||||
|
self.bom_qty = bom.quantity
|
||||||
|
|
||||||
for item in bom.get("items", []):
|
for item in bom.get("items", []):
|
||||||
qty = item.qty / bom.quantity # quantity per unit
|
qty = item.stock_qty / bom.quantity # quantity per unit
|
||||||
exploded_qty = self.exploded_qty * qty
|
exploded_qty = self.exploded_qty * qty
|
||||||
if item.bom_no:
|
if item.bom_no:
|
||||||
child = BOMTree(item.bom_no, exploded_qty=exploded_qty, qty=qty)
|
child = BOMTree(item.bom_no, exploded_qty=exploded_qty, qty=qty)
|
||||||
|
|||||||
@@ -682,7 +682,7 @@ class WorkOrder(Document):
|
|||||||
|
|
||||||
for node in bom_traversal:
|
for node in bom_traversal:
|
||||||
if node.is_bom:
|
if node.is_bom:
|
||||||
operations.extend(_get_operations(node.name, qty=node.exploded_qty))
|
operations.extend(_get_operations(node.name, qty=node.exploded_qty / node.bom_qty))
|
||||||
|
|
||||||
bom_qty = frappe.get_cached_value("BOM", self.bom_no, "quantity")
|
bom_qty = frappe.get_cached_value("BOM", self.bom_no, "quantity")
|
||||||
operations.extend(_get_operations(self.bom_no, qty=1.0 / bom_qty))
|
operations.extend(_get_operations(self.bom_no, qty=1.0 / bom_qty))
|
||||||
|
|||||||
@@ -808,7 +808,7 @@ def get_default_company_address(name, sort_key="is_primary_address", existing_ad
|
|||||||
return existing_address
|
return existing_address
|
||||||
|
|
||||||
if out:
|
if out:
|
||||||
return min(out, key=lambda x: x[1])[0] # find min by sort_key
|
return max(out, key=lambda x: x[1])[0] # find max by sort_key
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from frappe.utils import random_string
|
|||||||
from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import (
|
from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import (
|
||||||
get_charts_for_country,
|
get_charts_for_country,
|
||||||
)
|
)
|
||||||
|
from erpnext.setup.doctype.company.company import get_default_company_address
|
||||||
|
|
||||||
test_ignore = ["Account", "Cost Center", "Payment Terms Template", "Salary Component", "Warehouse"]
|
test_ignore = ["Account", "Cost Center", "Payment Terms Template", "Salary Component", "Warehouse"]
|
||||||
test_dependencies = ["Fiscal Year"]
|
test_dependencies = ["Fiscal Year"]
|
||||||
@@ -132,6 +133,38 @@ class TestCompany(unittest.TestCase):
|
|||||||
self.assertTrue(lft >= min_lft)
|
self.assertTrue(lft >= min_lft)
|
||||||
self.assertTrue(rgt <= max_rgt)
|
self.assertTrue(rgt <= max_rgt)
|
||||||
|
|
||||||
|
def test_primary_address(self):
|
||||||
|
company = "_Test Company"
|
||||||
|
|
||||||
|
secondary = frappe.get_doc(
|
||||||
|
{
|
||||||
|
"address_title": "Non Primary",
|
||||||
|
"doctype": "Address",
|
||||||
|
"address_type": "Billing",
|
||||||
|
"address_line1": "Something",
|
||||||
|
"city": "Mumbai",
|
||||||
|
"state": "Maharashtra",
|
||||||
|
"country": "India",
|
||||||
|
"is_primary_address": 1,
|
||||||
|
"pincode": "400098",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"link_doctype": "Company",
|
||||||
|
"link_name": company,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
secondary.insert()
|
||||||
|
self.addCleanup(secondary.delete)
|
||||||
|
|
||||||
|
primary = frappe.copy_doc(secondary)
|
||||||
|
primary.is_primary_address = 1
|
||||||
|
primary.insert()
|
||||||
|
self.addCleanup(primary.delete)
|
||||||
|
|
||||||
|
self.assertEqual(get_default_company_address(company), primary.name)
|
||||||
|
|
||||||
def get_no_of_children(self, company):
|
def get_no_of_children(self, company):
|
||||||
def get_no_of_children(companies, no_of_children):
|
def get_no_of_children(companies, no_of_children):
|
||||||
children = []
|
children = []
|
||||||
|
|||||||
Reference in New Issue
Block a user