mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-05 14:38:26 +00:00
changes for the default cost center
This commit is contained in:
@@ -14,6 +14,7 @@ from frappe.desk.notifications import clear_doctype_notifications
|
|||||||
from erpnext.buying.utils import validate_for_items, check_for_closed_status
|
from erpnext.buying.utils import validate_for_items, check_for_closed_status
|
||||||
from erpnext.stock.utils import get_bin
|
from erpnext.stock.utils import get_bin
|
||||||
from six import string_types
|
from six import string_types
|
||||||
|
from erpnext.stock.doctype.item.item import get_item_defaults
|
||||||
|
|
||||||
form_grid_templates = {
|
form_grid_templates = {
|
||||||
"items": "templates/form_grid/item_grid.html"
|
"items": "templates/form_grid/item_grid.html"
|
||||||
@@ -374,7 +375,7 @@ def make_purchase_invoice(source_name, target_doc=None):
|
|||||||
target.base_amount = target.amount * flt(source_parent.conversion_rate)
|
target.base_amount = target.amount * flt(source_parent.conversion_rate)
|
||||||
target.qty = target.amount / flt(obj.rate) if (flt(obj.rate) and flt(obj.billed_amt)) else flt(obj.qty)
|
target.qty = target.amount / flt(obj.rate) if (flt(obj.rate) and flt(obj.billed_amt)) else flt(obj.qty)
|
||||||
|
|
||||||
item = frappe.db.get_value("Item", target.item_code, ["item_group", "buying_cost_center"], as_dict=1)
|
item = get_item_defaults(target.item_code, target.company)
|
||||||
target.cost_center = frappe.db.get_value("Project", obj.project, "cost_center") \
|
target.cost_center = frappe.db.get_value("Project", obj.project, "cost_center") \
|
||||||
or item.buying_cost_center \
|
or item.buying_cost_center \
|
||||||
or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")
|
or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ from frappe.contacts.doctype.address.address import get_company_address
|
|||||||
from erpnext.controllers.selling_controller import SellingController
|
from erpnext.controllers.selling_controller import SellingController
|
||||||
from frappe.desk.doctype.auto_repeat.auto_repeat import get_next_schedule_date
|
from frappe.desk.doctype.auto_repeat.auto_repeat import get_next_schedule_date
|
||||||
from erpnext.selling.doctype.customer.customer import check_credit_limit
|
from erpnext.selling.doctype.customer.customer import check_credit_limit
|
||||||
|
from erpnext.stock.doctype.item.item import get_item_defaults
|
||||||
|
|
||||||
|
|
||||||
form_grid_templates = {
|
form_grid_templates = {
|
||||||
"items": "templates/form_grid/item_grid.html"
|
"items": "templates/form_grid/item_grid.html"
|
||||||
@@ -493,7 +495,7 @@ def make_delivery_note(source_name, target_doc=None):
|
|||||||
target.amount = (flt(source.qty) - flt(source.delivered_qty)) * flt(source.rate)
|
target.amount = (flt(source.qty) - flt(source.delivered_qty)) * flt(source.rate)
|
||||||
target.qty = flt(source.qty) - flt(source.delivered_qty)
|
target.qty = flt(source.qty) - flt(source.delivered_qty)
|
||||||
|
|
||||||
item = frappe.db.get_value("Item", target.item_code, ["item_group", "selling_cost_center"], as_dict=1)
|
item = get_item_defaults(target.item_code, target.company)
|
||||||
|
|
||||||
if item:
|
if item:
|
||||||
target.cost_center = frappe.db.get_value("Project", source_parent.project, "cost_center") \
|
target.cost_center = frappe.db.get_value("Project", source_parent.project, "cost_center") \
|
||||||
@@ -557,7 +559,7 @@ def make_sales_invoice(source_name, target_doc=None, ignore_permissions=False):
|
|||||||
if source_parent.project:
|
if source_parent.project:
|
||||||
target.cost_center = frappe.db.get_value("Project", source_parent.project, "cost_center")
|
target.cost_center = frappe.db.get_value("Project", source_parent.project, "cost_center")
|
||||||
if not target.cost_center and target.item_code:
|
if not target.cost_center and target.item_code:
|
||||||
item = frappe.db.get_value("Item", target.item_code, ["item_group", "selling_cost_center"], as_dict=1)
|
item = get_item_defaults(target.item_code, target.company)
|
||||||
target.cost_center = item.selling_cost_center \
|
target.cost_center = item.selling_cost_center \
|
||||||
or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")
|
or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")
|
||||||
|
|
||||||
|
|||||||
@@ -291,9 +291,6 @@ class Company(NestedSet):
|
|||||||
Trash accounts and cost centers for this company if no gl entry exists
|
Trash accounts and cost centers for this company if no gl entry exists
|
||||||
"""
|
"""
|
||||||
self.update_nsm_model()
|
self.update_nsm_model()
|
||||||
accounts = frappe.db.sql_list("select name from tabAccount where company=%s", self.name)
|
|
||||||
cost_centers = frappe.db.sql_list("select name from `tabCost Center` where company=%s", self.name)
|
|
||||||
warehouses = frappe.db.sql_list("select name from tabWarehouse where company=%s", self.name)
|
|
||||||
|
|
||||||
rec = frappe.db.sql("SELECT name from `tabGL Entry` where company = %s", self.name)
|
rec = frappe.db.sql("SELECT name from `tabGL Entry` where company = %s", self.name)
|
||||||
if not rec:
|
if not rec:
|
||||||
@@ -308,33 +305,19 @@ class Company(NestedSet):
|
|||||||
frappe.db.sql("""delete from `tabWarehouse` where company=%s""", self.name)
|
frappe.db.sql("""delete from `tabWarehouse` where company=%s""", self.name)
|
||||||
|
|
||||||
frappe.defaults.clear_default("company", value=self.name)
|
frappe.defaults.clear_default("company", value=self.name)
|
||||||
frappe.db.sql("delete from `tabMode of Payment Account` where company=%s", self.name)
|
for doctype in ["Mode of Payment Account", "Item Default"]:
|
||||||
|
frappe.db.sql("delete from `tab{0}` where company = %s".format(doctype), self.name)
|
||||||
|
|
||||||
# clear default accounts, warehouses from item
|
# clear default accounts, warehouses from item
|
||||||
|
warehouses = frappe.db.sql_list("select name from tabWarehouse where company=%s", self.name)
|
||||||
if warehouses:
|
if warehouses:
|
||||||
for f in ["default_warehouse", "website_warehouse"]:
|
|
||||||
frappe.db.sql("""update `tabItem Default` set %s=NULL where company=%s and %s in (%s)"""
|
|
||||||
% (f, self.name, f, ', '.join(['%s']*len(warehouses))), tuple(warehouses))
|
|
||||||
|
|
||||||
frappe.db.sql("""delete from `tabItem Reorder` where warehouse in (%s)"""
|
frappe.db.sql("""delete from `tabItem Reorder` where warehouse in (%s)"""
|
||||||
% ', '.join(['%s']*len(warehouses)), tuple(warehouses))
|
% ', '.join(['%s']*len(warehouses)), tuple(warehouses))
|
||||||
|
|
||||||
if accounts:
|
|
||||||
for f in ["income_account", "expense_account"]:
|
|
||||||
frappe.db.sql("""update tabItem set %s=NULL where %s in (%s)"""
|
|
||||||
% (f, f, ', '.join(['%s']*len(accounts))), tuple(accounts))
|
|
||||||
|
|
||||||
if cost_centers:
|
|
||||||
for f in ["selling_cost_center", "buying_cost_center"]:
|
|
||||||
frappe.db.sql("""update tabItem set %s=NULL where %s in (%s)"""
|
|
||||||
% (f, f, ', '.join(['%s']*len(cost_centers))), tuple(cost_centers))
|
|
||||||
|
|
||||||
# reset default company
|
# reset default company
|
||||||
frappe.db.sql("""update `tabSingles` set value=""
|
frappe.db.sql("""update `tabSingles` set value=""
|
||||||
where doctype='Global Defaults' and field='default_company'
|
where doctype='Global Defaults' and field='default_company'
|
||||||
and value=%s""", self.name)
|
and value=%s""", self.name)
|
||||||
# delete mode of payment account
|
|
||||||
frappe.db.sql("delete from `tabMode of Payment Account` where company=%s", self.name)
|
|
||||||
|
|
||||||
# delete BOMs
|
# delete BOMs
|
||||||
boms = frappe.db.sql_list("select name from tabBOM where company=%s", self.name)
|
boms = frappe.db.sql_list("select name from tabBOM where company=%s", self.name)
|
||||||
|
|||||||
@@ -883,13 +883,13 @@ def check_stock_uom_with_bin(item, stock_uom):
|
|||||||
frappe.throw(
|
frappe.throw(
|
||||||
_("Default Unit of Measure for Item {0} cannot be changed directly because you have already made some transaction(s) with another UOM. You will need to create a new Item to use a different Default UOM.").format(item))
|
_("Default Unit of Measure for Item {0} cannot be changed directly because you have already made some transaction(s) with another UOM. You will need to create a new Item to use a different Default UOM.").format(item))
|
||||||
|
|
||||||
def get_item_details(item, company):
|
def get_item_defaults(item, company):
|
||||||
return frappe.db.sql('''
|
return frappe.db.sql('''
|
||||||
select
|
select
|
||||||
i.item_name, i.description, i.stock_uom, i.name, i.is_stock_item, i.item_code
|
i.item_name, i.description, i.stock_uom, i.name, i.is_stock_item, i.item_code, i.item_group,
|
||||||
id.expense_account, id.buying_cost_center, id.warehouse
|
id.expense_account, id.buying_cost_center, id.default_warehouse, id.selling_cost_center
|
||||||
from
|
from
|
||||||
`tabItem` i, `tabItem Default` id
|
`tabItem` i, `tabItem Default` id
|
||||||
where
|
where
|
||||||
i.name = id.parent and i.name = %s and id.company = %s
|
i.name = id.parent and i.name = %s and id.company = %s
|
||||||
''', (item, company), as_dict=1)
|
''', (item, company), as_dict=1)[0]
|
||||||
@@ -36,7 +36,7 @@ def make_item(item_code, properties=None):
|
|||||||
|
|
||||||
|
|
||||||
if item.is_stock_item:
|
if item.is_stock_item:
|
||||||
for item_default in [doc for doc in item.item_defaults if not doc.default_warehouse]
|
for item_default in [doc for doc in item.item_defaults if not doc.default_warehouse]:
|
||||||
item_default.default_warehouse = "_Test Warehouse - _TC"
|
item_default.default_warehouse = "_Test Warehouse - _TC"
|
||||||
|
|
||||||
item.insert()
|
item.insert()
|
||||||
@@ -205,7 +205,7 @@ class TestItem(unittest.TestCase):
|
|||||||
"default_warehouse": "_Test Warehouse - _TC",
|
"default_warehouse": "_Test Warehouse - _TC",
|
||||||
"company": "_Test Company"
|
"company": "_Test Company"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
"has_variants": 1
|
"has_variants": 1
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from erpnext.stock.utils import get_incoming_rate
|
|||||||
from erpnext.stock.stock_ledger import get_previous_sle, NegativeStockError, get_valuation_rate
|
from erpnext.stock.stock_ledger import get_previous_sle, NegativeStockError, get_valuation_rate
|
||||||
from erpnext.stock.get_item_details import get_bin_details, get_default_cost_center, get_conversion_factor
|
from erpnext.stock.get_item_details import get_bin_details, get_default_cost_center, get_conversion_factor
|
||||||
from erpnext.stock.doctype.batch.batch import get_batch_no, set_batch_nos, get_batch_qty
|
from erpnext.stock.doctype.batch.batch import get_batch_no, set_batch_nos, get_batch_qty
|
||||||
from erpnext.stock.doctype.item.item import get_item_details
|
from erpnext.stock.doctype.item.item import get_item_defaults
|
||||||
from erpnext.manufacturing.doctype.bom.bom import validate_bom_no
|
from erpnext.manufacturing.doctype.bom.bom import validate_bom_no
|
||||||
from erpnext.stock.utils import get_bin
|
from erpnext.stock.utils import get_bin
|
||||||
import json
|
import json
|
||||||
@@ -563,14 +563,14 @@ class StockEntry(StockController):
|
|||||||
pro_doc.run_method("update_planned_qty")
|
pro_doc.run_method("update_planned_qty")
|
||||||
|
|
||||||
def get_item_details(self, args=None, for_update=False):
|
def get_item_details(self, args=None, for_update=False):
|
||||||
item = frappe.db.sql("""select stock_uom, description, image, item_name,
|
item = frappe.db.sql("""select i.stock_uom, i.description, i.image, i.item_name, i.item_group,
|
||||||
expense_account, buying_cost_center, item_group, has_serial_no,
|
i.has_batch_no, i.sample_quantity, i.has_serial_no,
|
||||||
has_batch_no, sample_quantity
|
id.expense_account, id.buying_cost_center
|
||||||
from `tabItem`
|
from `tabItem`, `tabItem Default` id
|
||||||
where name = %s
|
where i.name=%s and i.name=id.parent and id.company=%s
|
||||||
and disabled=0
|
and i.disabled=0
|
||||||
and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)""",
|
and (i.end_of_life is null or i.end_of_life='0000-00-00' or i.end_of_life > %s)""",
|
||||||
(args.get('item_code'), nowdate()), as_dict = 1)
|
(args.get('item_code'), self.company, nowdate()), as_dict = 1)
|
||||||
if not item:
|
if not item:
|
||||||
frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get("item_code")))
|
frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get("item_code")))
|
||||||
|
|
||||||
@@ -717,7 +717,7 @@ class StockEntry(StockController):
|
|||||||
item_code = frappe.db.get_value("BOM", self.bom_no, "item")
|
item_code = frappe.db.get_value("BOM", self.bom_no, "item")
|
||||||
to_warehouse = self.to_warehouse
|
to_warehouse = self.to_warehouse
|
||||||
|
|
||||||
item = get_item_details(item_code, self.company)
|
item = get_item_defaults(item_code, self.company)
|
||||||
|
|
||||||
if not self.work_order and not to_warehouse:
|
if not self.work_order and not to_warehouse:
|
||||||
# in case of BOM
|
# in case of BOM
|
||||||
@@ -783,7 +783,7 @@ class StockEntry(StockController):
|
|||||||
for item in wo_items:
|
for item in wo_items:
|
||||||
qty = item.required_qty
|
qty = item.required_qty
|
||||||
|
|
||||||
item_account_details = get_item_details(item.item_code, self.company)
|
item_account_details = get_item_defaults(item.item_code, self.company)
|
||||||
# Take into account consumption if there are any.
|
# Take into account consumption if there are any.
|
||||||
if self.purpose == 'Manufacture':
|
if self.purpose == 'Manufacture':
|
||||||
req_qty_each = flt(item.required_qty / wo.qty)
|
req_qty_each = flt(item.required_qty / wo.qty)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from erpnext.setup.utils import get_exchange_rate
|
|||||||
from frappe.model.meta import get_field_precision
|
from frappe.model.meta import get_field_precision
|
||||||
from erpnext.stock.doctype.batch.batch import get_batch_no
|
from erpnext.stock.doctype.batch.batch import get_batch_no
|
||||||
from erpnext import get_company_currency
|
from erpnext import get_company_currency
|
||||||
from erpnext.stock.doctype.item.item import get_item_details
|
from erpnext.stock.doctype.item.item import get_item_defaults
|
||||||
|
|
||||||
|
|
||||||
from six import string_types, iteritems
|
from six import string_types, iteritems
|
||||||
@@ -206,9 +206,8 @@ def get_basic_details(args, item):
|
|||||||
user_default_warehouse = user_default_warehouse_list[0] \
|
user_default_warehouse = user_default_warehouse_list[0] \
|
||||||
if len(user_default_warehouse_list) == 1 else ""
|
if len(user_default_warehouse_list) == 1 else ""
|
||||||
|
|
||||||
item_default_warehouse = [default.default_warehouse for default in item.item_defaults if default.company == args.company]
|
item_defaults = get_item_defaults(item.name, args.company)
|
||||||
item_default_warehouse = item_default_warehouse[0] if item_default_warehouse else None
|
warehouse = user_default_warehouse or item_defaults.default_warehouse or args.warehouse
|
||||||
warehouse = user_default_warehouse or item_default_warehouse or args.warehouse
|
|
||||||
|
|
||||||
material_request_type = ''
|
material_request_type = ''
|
||||||
if args.get('doctype') == "Material Request":
|
if args.get('doctype') == "Material Request":
|
||||||
@@ -231,9 +230,9 @@ def get_basic_details(args, item):
|
|||||||
"description": cstr(item.description).strip(),
|
"description": cstr(item.description).strip(),
|
||||||
"image": cstr(item.image).strip(),
|
"image": cstr(item.image).strip(),
|
||||||
"warehouse": warehouse,
|
"warehouse": warehouse,
|
||||||
"income_account": get_default_income_account(args, item),
|
"income_account": get_default_income_account(args, item_defaults),
|
||||||
"expense_account": get_default_expense_account(args, item),
|
"expense_account": get_default_expense_account(args, item_defaults),
|
||||||
"cost_center": get_default_cost_center(args, item),
|
"cost_center": get_default_cost_center(args, item_defaults),
|
||||||
'has_serial_no': item.has_serial_no,
|
'has_serial_no': item.has_serial_no,
|
||||||
'has_batch_no': item.has_batch_no,
|
'has_batch_no': item.has_batch_no,
|
||||||
"batch_no": None,
|
"batch_no": None,
|
||||||
@@ -682,7 +681,7 @@ def get_default_bom(item_code=None):
|
|||||||
return bom
|
return bom
|
||||||
|
|
||||||
def get_valuation_rate(item_code, company, warehouse=None):
|
def get_valuation_rate(item_code, company, warehouse=None):
|
||||||
item = get_item_details(item_code, company)
|
item = get_item_defaults(item_code, company)
|
||||||
# item = frappe.get_doc("Item", item_code)
|
# item = frappe.get_doc("Item", item_code)
|
||||||
if item.is_stock_item:
|
if item.is_stock_item:
|
||||||
if not warehouse:
|
if not warehouse:
|
||||||
|
|||||||
Reference in New Issue
Block a user