fix: copy accounting dimensions to asset and sales invoice (#44964)
* fix: copy accounting dimensions to asset and sales invoice
* fix: replace sql query with query builder
* refactor: reuse function for accounting dimensions
* fix: loop handling
* fix: use explicit param
(cherry picked from commit 079ec864de)
# Conflicts:
# erpnext/controllers/buying_controller.py
This commit is contained in:
@@ -19,6 +19,7 @@ from frappe.utils import (
|
||||
)
|
||||
|
||||
import erpnext
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_dimensions
|
||||
from erpnext.accounts.general_ledger import make_reverse_gl_entries
|
||||
from erpnext.assets.doctype.asset.depreciation import (
|
||||
get_comma_separated_links,
|
||||
@@ -887,6 +888,7 @@ def get_asset_naming_series():
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_sales_invoice(asset, item_code, company, serial_no=None):
|
||||
asset_doc = frappe.get_doc("Asset", asset)
|
||||
si = frappe.new_doc("Sales Invoice")
|
||||
si.company = company
|
||||
si.currency = frappe.get_cached_value("Company", company, "default_currency")
|
||||
@@ -903,6 +905,16 @@ def make_sales_invoice(asset, item_code, company, serial_no=None):
|
||||
"qty": 1,
|
||||
},
|
||||
)
|
||||
|
||||
accounting_dimensions = get_dimensions(with_cost_center_and_project=True)
|
||||
for dimension in accounting_dimensions[0]:
|
||||
si.update(
|
||||
{
|
||||
dimension["fieldname"]: asset_doc.get(dimension["fieldname"])
|
||||
or dimension.get("default_dimension")
|
||||
}
|
||||
)
|
||||
|
||||
si.set_missing_values()
|
||||
return si
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from frappe.utils import cint, flt, getdate
|
||||
from frappe.utils.data import nowtime
|
||||
|
||||
import erpnext
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_dimensions
|
||||
from erpnext.accounts.doctype.budget.budget import validate_expense_against_budget
|
||||
from erpnext.accounts.party import get_party_details
|
||||
from erpnext.buying.utils import update_last_purchase_rate, validate_for_items
|
||||
@@ -744,6 +745,11 @@ class BuyingController(SubcontractingController):
|
||||
def auto_make_assets(self, asset_items):
|
||||
items_data = get_asset_item_details(asset_items)
|
||||
messages = []
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
alert = False
|
||||
accounting_dimensions = get_dimensions(with_cost_center_and_project=True)
|
||||
>>>>>>> 079ec864de (fix: copy accounting dimensions to asset and sales invoice (#44964))
|
||||
|
||||
for d in self.items:
|
||||
if d.is_fixed_asset:
|
||||
@@ -755,11 +761,11 @@ class BuyingController(SubcontractingController):
|
||||
if item_data.get("asset_naming_series"):
|
||||
created_assets = []
|
||||
if item_data.get("is_grouped_asset"):
|
||||
asset = self.make_asset(d, is_grouped_asset=True)
|
||||
asset = self.make_asset(d, accounting_dimensions, is_grouped_asset=True)
|
||||
created_assets.append(asset)
|
||||
else:
|
||||
for _qty in range(cint(d.qty)):
|
||||
asset = self.make_asset(d)
|
||||
asset = self.make_asset(d, accounting_dimensions)
|
||||
created_assets.append(asset)
|
||||
|
||||
if len(created_assets) > 5:
|
||||
@@ -797,7 +803,7 @@ class BuyingController(SubcontractingController):
|
||||
for message in messages:
|
||||
frappe.msgprint(message, title="Success", indicator="green")
|
||||
|
||||
def make_asset(self, row, is_grouped_asset=False):
|
||||
def make_asset(self, row, accounting_dimensions, is_grouped_asset=False):
|
||||
if not row.asset_location:
|
||||
frappe.throw(_("Row {0}: Enter location for the asset item {1}").format(row.idx, row.item_code))
|
||||
|
||||
@@ -828,6 +834,13 @@ class BuyingController(SubcontractingController):
|
||||
"purchase_invoice_item": row.name if self.doctype == "Purchase Invoice" else None,
|
||||
}
|
||||
)
|
||||
for dimension in accounting_dimensions[0]:
|
||||
asset.update(
|
||||
{
|
||||
dimension["fieldname"]: self.get(dimension["fieldname"])
|
||||
or dimension.get("default_dimension")
|
||||
}
|
||||
)
|
||||
|
||||
asset.flags.ignore_validate = True
|
||||
asset.flags.ignore_mandatory = True
|
||||
|
||||
Reference in New Issue
Block a user