mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 03:09:09 +00:00
Merge branch 'wsgi' of https://github.com/webnotes/erpnext into i18n
Conflicts: accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js public/js/complete_setup.js selling/doctype/opportunity/opportunity.js selling/doctype/quotation/quotation.js
This commit is contained in:
@@ -9,7 +9,6 @@ from webnotes.model.bean import getlist
|
||||
from webnotes.model.code import get_obj
|
||||
from webnotes import msgprint, _
|
||||
|
||||
sql = webnotes.conn.sql
|
||||
|
||||
|
||||
class DocType:
|
||||
@@ -18,7 +17,7 @@ class DocType:
|
||||
self.doclist = doclist
|
||||
|
||||
def autoname(self):
|
||||
last_name = sql("""select max(name) from `tabBOM`
|
||||
last_name = webnotes.conn.sql("""select max(name) from `tabBOM`
|
||||
where name like "BOM/%s/%%" """ % cstr(self.doc.item).replace('"', '\\"'))
|
||||
if last_name:
|
||||
idx = cint(cstr(last_name[0][0]).split('/')[-1].split('-')[0]) + 1
|
||||
@@ -144,7 +143,7 @@ class DocType:
|
||||
webnotes.bean(self.doclist).update_after_submit()
|
||||
|
||||
def get_bom_unitcost(self, bom_no):
|
||||
bom = sql("""select name, total_cost/quantity as unit_cost from `tabBOM`
|
||||
bom = webnotes.conn.sql("""select name, total_cost/quantity as unit_cost from `tabBOM`
|
||||
where is_active = 1 and name = %s""", bom_no, as_dict=1)
|
||||
return bom and bom[0]['unit_cost'] or 0
|
||||
|
||||
@@ -156,7 +155,7 @@ class DocType:
|
||||
from stock.utils import get_incoming_rate
|
||||
dt = self.doc.costing_date or nowdate()
|
||||
time = self.doc.costing_date == nowdate() and now().split()[1] or '23:59'
|
||||
warehouse = sql("select warehouse from `tabBin` where item_code = %s", args['item_code'])
|
||||
warehouse = webnotes.conn.sql("select warehouse from `tabBin` where item_code = %s", args['item_code'])
|
||||
rate = []
|
||||
for wh in warehouse:
|
||||
r = get_incoming_rate({
|
||||
@@ -184,7 +183,7 @@ class DocType:
|
||||
if not self.doc.is_active:
|
||||
webnotes.conn.set(self.doc, "is_default", 0)
|
||||
|
||||
sql("update `tabItem` set default_bom = null where name = %s and default_bom = %s",
|
||||
webnotes.conn.sql("update `tabItem` set default_bom = null where name = %s and default_bom = %s",
|
||||
(self.doc.item, self.doc.name))
|
||||
|
||||
def clear_operations(self):
|
||||
@@ -250,7 +249,7 @@ class DocType:
|
||||
|
||||
def validate_bom_no(self, item, bom_no, idx):
|
||||
"""Validate BOM No of sub-contracted items"""
|
||||
bom = sql("""select name from `tabBOM` where name = %s and item = %s
|
||||
bom = webnotes.conn.sql("""select name from `tabBOM` where name = %s and item = %s
|
||||
and is_active=1 and docstatus=1""",
|
||||
(bom_no, item), as_dict =1)
|
||||
if not bom:
|
||||
@@ -272,7 +271,7 @@ class DocType:
|
||||
for d in check_list:
|
||||
bom_list, count = [self.doc.name], 0
|
||||
while (len(bom_list) > count ):
|
||||
boms = sql(" select %s from `tabBOM Item` where %s = '%s' " %
|
||||
boms = webnotes.conn.sql(" select %s from `tabBOM Item` where %s = '%s' " %
|
||||
(d[0], d[1], cstr(bom_list[count])))
|
||||
count = count + 1
|
||||
for b in boms:
|
||||
@@ -333,6 +332,7 @@ class DocType:
|
||||
d.amount = flt(d.rate) * flt(d.qty)
|
||||
d.qty_consumed_per_unit = flt(d.qty) / flt(self.doc.quantity)
|
||||
total_rm_cost += d.amount
|
||||
|
||||
self.doc.raw_material_cost = total_rm_cost
|
||||
|
||||
def update_exploded_items(self):
|
||||
@@ -364,7 +364,7 @@ class DocType:
|
||||
def get_child_exploded_items(self, bom_no, qty):
|
||||
""" Add all items from Flat BOM of child BOM"""
|
||||
|
||||
child_fb_items = sql("""select item_code, description, stock_uom, qty, rate,
|
||||
child_fb_items = webnotes.conn.sql("""select item_code, description, stock_uom, qty, rate,
|
||||
qty_consumed_per_unit from `tabBOM Explosion Item`
|
||||
where parent = %s and docstatus = 1""", bom_no, as_dict = 1)
|
||||
|
||||
@@ -390,12 +390,12 @@ class DocType:
|
||||
ch.save(1)
|
||||
|
||||
def get_parent_bom_list(self, bom_no):
|
||||
p_bom = sql("select parent from `tabBOM Item` where bom_no = '%s'" % bom_no)
|
||||
p_bom = webnotes.conn.sql("select parent from `tabBOM Item` where bom_no = '%s'" % bom_no)
|
||||
return p_bom and [i[0] for i in p_bom] or []
|
||||
|
||||
def validate_bom_links(self):
|
||||
if not self.doc.is_active:
|
||||
act_pbom = sql("""select distinct bom_item.parent from `tabBOM Item` bom_item
|
||||
act_pbom = webnotes.conn.sql("""select distinct bom_item.parent from `tabBOM Item` bom_item
|
||||
where bom_item.bom_no = %s and bom_item.docstatus = 1
|
||||
and exists (select * from `tabBOM` where name = bom_item.parent
|
||||
and docstatus = 1 and is_active = 1)""", self.doc.name)
|
||||
@@ -403,4 +403,53 @@ class DocType:
|
||||
if act_pbom and act_pbom[0][0]:
|
||||
action = self.doc.docstatus < 2 and _("deactivate") or _("cancel")
|
||||
msgprint(_("Cannot ") + action + _(": It is linked to other active BOM(s)"),
|
||||
raise_exception=1)
|
||||
raise_exception=1)
|
||||
|
||||
def get_bom_items_as_dict(bom, qty=1, fetch_exploded=1):
|
||||
item_dict = {}
|
||||
|
||||
query = """select
|
||||
bom_item.item_code,
|
||||
ifnull(sum(bom_item.qty_consumed_per_unit),0) * %(qty)s as qty,
|
||||
item.description,
|
||||
item.stock_uom,
|
||||
item.default_warehouse
|
||||
from
|
||||
`tab%(table)s` bom_item, `tabItem` item
|
||||
where
|
||||
bom_item.docstatus < 2
|
||||
and bom_item.parent = "%(bom)s"
|
||||
and item.name = bom_item.item_code
|
||||
%(conditions)s
|
||||
group by item_code, stock_uom"""
|
||||
|
||||
if fetch_exploded:
|
||||
items = webnotes.conn.sql(query % {
|
||||
"qty": qty,
|
||||
"table": "BOM Explosion Item",
|
||||
"bom": bom,
|
||||
"conditions": """and ifnull(item.is_pro_applicable, 'No') = 'No'
|
||||
and ifnull(item.is_sub_contracted_item, 'No') = 'No' """
|
||||
}, as_dict=True)
|
||||
else:
|
||||
items = webnotes.conn.sql(query % {
|
||||
"qty": qty,
|
||||
"table": "BOM Item",
|
||||
"bom": bom,
|
||||
"conditions": ""
|
||||
}, as_dict=True)
|
||||
|
||||
# make unique
|
||||
for item in items:
|
||||
if item_dict.has_key(item.item_code):
|
||||
item_dict[item.item_code]["qty"] += flt(item.qty)
|
||||
else:
|
||||
item_dict[item.item_code] = item
|
||||
|
||||
return item_dict
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_bom_items(bom, qty=1, fetch_exploded=1):
|
||||
items = get_bom_items_as_dict(bom, qty, fetch_exploded).values()
|
||||
items.sort(lambda a, b: a.item_code > b.item_code and 1 or -1)
|
||||
return items
|
||||
@@ -7,6 +7,35 @@ import unittest
|
||||
import webnotes
|
||||
|
||||
test_records = [
|
||||
[
|
||||
{
|
||||
"doctype": "BOM",
|
||||
"item": "_Test Item Home Desktop Manufactured",
|
||||
"quantity": 1.0,
|
||||
"is_active": 1,
|
||||
"is_default": 1,
|
||||
"docstatus": 1
|
||||
},
|
||||
{
|
||||
"doctype": "BOM Item",
|
||||
"item_code": "_Test Serialized Item With Series",
|
||||
"parentfield": "bom_materials",
|
||||
"qty": 1.0,
|
||||
"rate": 5000.0,
|
||||
"amount": 5000.0,
|
||||
"stock_uom": "_Test UOM"
|
||||
},
|
||||
{
|
||||
"doctype": "BOM Item",
|
||||
"item_code": "_Test Item 2",
|
||||
"parentfield": "bom_materials",
|
||||
"qty": 2.0,
|
||||
"rate": 1000.0,
|
||||
"amount": 2000.0,
|
||||
"stock_uom": "_Test UOM"
|
||||
}
|
||||
],
|
||||
|
||||
[
|
||||
{
|
||||
"doctype": "BOM",
|
||||
@@ -34,5 +63,57 @@ test_records = [
|
||||
"amount": 2000.0,
|
||||
"stock_uom": "_Test UOM"
|
||||
}
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
[
|
||||
{
|
||||
"doctype": "BOM",
|
||||
"item": "_Test FG Item 2",
|
||||
"quantity": 1.0,
|
||||
"is_active": 1,
|
||||
"is_default": 1,
|
||||
"docstatus": 1
|
||||
},
|
||||
{
|
||||
"doctype": "BOM Item",
|
||||
"item_code": "_Test Item",
|
||||
"parentfield": "bom_materials",
|
||||
"qty": 1.0,
|
||||
"rate": 5000.0,
|
||||
"amount": 5000.0,
|
||||
"stock_uom": "_Test UOM"
|
||||
},
|
||||
{
|
||||
"doctype": "BOM Item",
|
||||
"item_code": "_Test Item Home Desktop Manufactured",
|
||||
"bom_no": "BOM/_Test Item Home Desktop Manufactured/001",
|
||||
"parentfield": "bom_materials",
|
||||
"qty": 2.0,
|
||||
"rate": 1000.0,
|
||||
"amount": 2000.0,
|
||||
"stock_uom": "_Test UOM"
|
||||
}
|
||||
],
|
||||
]
|
||||
|
||||
class TestBOM(unittest.TestCase):
|
||||
def test_get_items(self):
|
||||
from manufacturing.doctype.bom.bom import get_bom_items_as_dict
|
||||
items_dict = get_bom_items_as_dict(bom="BOM/_Test FG Item 2/001", qty=1, fetch_exploded=0)
|
||||
self.assertTrue(test_records[2][1]["item_code"] in items_dict)
|
||||
self.assertTrue(test_records[2][2]["item_code"] in items_dict)
|
||||
self.assertEquals(len(items_dict.values()), 2)
|
||||
|
||||
def test_get_items_exploded(self):
|
||||
from manufacturing.doctype.bom.bom import get_bom_items_as_dict
|
||||
items_dict = get_bom_items_as_dict(bom="BOM/_Test FG Item 2/001", qty=1, fetch_exploded=1)
|
||||
self.assertTrue(test_records[2][1]["item_code"] in items_dict)
|
||||
self.assertFalse(test_records[2][2]["item_code"] in items_dict)
|
||||
self.assertTrue(test_records[0][1]["item_code"] in items_dict)
|
||||
self.assertTrue(test_records[0][2]["item_code"] in items_dict)
|
||||
self.assertEquals(len(items_dict.values()), 3)
|
||||
|
||||
def test_get_items_list(self):
|
||||
from manufacturing.doctype.bom.bom import get_bom_items
|
||||
self.assertEquals(len(get_bom_items(bom="BOM/_Test FG Item 2/001", qty=1, fetch_exploded=1)), 3)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user