mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-31 19:02:21 +02:00
* fix: incorrect cost center in the purchase invoice (#37591)
(cherry picked from commit 14b009b093)
# Conflicts:
# erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
* chore: fix conflicts
---------
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -1858,6 +1858,30 @@ class TestPurchaseInvoice(FrappeTestCase, StockTestMixin):
|
|||||||
pi.load_from_db()
|
pi.load_from_db()
|
||||||
self.assertFalse(pi.repost_required)
|
self.assertFalse(pi.repost_required)
|
||||||
|
|
||||||
|
def test_default_cost_center_for_purchase(self):
|
||||||
|
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
|
||||||
|
|
||||||
|
for c_center in ["_Test Cost Center Selling", "_Test Cost Center Buying"]:
|
||||||
|
create_cost_center(cost_center_name=c_center)
|
||||||
|
|
||||||
|
item = create_item(
|
||||||
|
"_Test Cost Center Item For Purchase",
|
||||||
|
is_stock_item=1,
|
||||||
|
buying_cost_center="_Test Cost Center Buying - _TC",
|
||||||
|
selling_cost_center="_Test Cost Center Selling - _TC",
|
||||||
|
)
|
||||||
|
|
||||||
|
pi = make_purchase_invoice(
|
||||||
|
item=item.name, qty=1, rate=1000, update_stock=True, do_not_submit=True, cost_center=""
|
||||||
|
)
|
||||||
|
|
||||||
|
pi.items[0].cost_center = ""
|
||||||
|
pi.set_missing_values()
|
||||||
|
pi.calculate_taxes_and_totals()
|
||||||
|
pi.save()
|
||||||
|
|
||||||
|
self.assertEqual(pi.items[0].cost_center, "_Test Cost Center Buying - _TC")
|
||||||
|
|
||||||
|
|
||||||
def check_gl_entries(
|
def check_gl_entries(
|
||||||
doc,
|
doc,
|
||||||
|
|||||||
@@ -893,6 +893,8 @@ def create_item(
|
|||||||
opening_stock=0,
|
opening_stock=0,
|
||||||
is_fixed_asset=0,
|
is_fixed_asset=0,
|
||||||
asset_category=None,
|
asset_category=None,
|
||||||
|
buying_cost_center=None,
|
||||||
|
selling_cost_center=None,
|
||||||
company="_Test Company",
|
company="_Test Company",
|
||||||
):
|
):
|
||||||
if not frappe.db.exists("Item", item_code):
|
if not frappe.db.exists("Item", item_code):
|
||||||
@@ -910,7 +912,15 @@ def create_item(
|
|||||||
item.is_purchase_item = is_purchase_item
|
item.is_purchase_item = is_purchase_item
|
||||||
item.is_customer_provided_item = is_customer_provided_item
|
item.is_customer_provided_item = is_customer_provided_item
|
||||||
item.customer = customer or ""
|
item.customer = customer or ""
|
||||||
item.append("item_defaults", {"default_warehouse": warehouse, "company": company})
|
item.append(
|
||||||
|
"item_defaults",
|
||||||
|
{
|
||||||
|
"default_warehouse": warehouse,
|
||||||
|
"company": company,
|
||||||
|
"selling_cost_center": selling_cost_center,
|
||||||
|
"buying_cost_center": buying_cost_center,
|
||||||
|
},
|
||||||
|
)
|
||||||
item.save()
|
item.save()
|
||||||
else:
|
else:
|
||||||
item = frappe.get_doc("Item", item_code)
|
item = frappe.get_doc("Item", item_code)
|
||||||
|
|||||||
@@ -771,6 +771,12 @@ def get_default_cost_center(args, item=None, item_group=None, brand=None, compan
|
|||||||
data = frappe.get_attr(path)(args.get("item_code"), company)
|
data = frappe.get_attr(path)(args.get("item_code"), company)
|
||||||
|
|
||||||
if data and (data.selling_cost_center or data.buying_cost_center):
|
if data and (data.selling_cost_center or data.buying_cost_center):
|
||||||
|
if args.get("customer") and data.selling_cost_center:
|
||||||
|
return data.selling_cost_center
|
||||||
|
|
||||||
|
elif args.get("supplier") and data.buying_cost_center:
|
||||||
|
return data.buying_cost_center
|
||||||
|
|
||||||
return data.selling_cost_center or data.buying_cost_center
|
return data.selling_cost_center or data.buying_cost_center
|
||||||
|
|
||||||
if not cost_center and args.get("cost_center"):
|
if not cost_center and args.get("cost_center"):
|
||||||
|
|||||||
Reference in New Issue
Block a user