Merge pull request #36962 from frappe/version-13-hotfix

chore: release v13
This commit is contained in:
Deepesh Garg
2023-09-06 12:52:49 +05:30
committed by GitHub
4 changed files with 174 additions and 44 deletions

View File

@@ -261,9 +261,7 @@ class PurchaseInvoice(BuyingController):
stock_not_billed_account = self.get_company_default("stock_received_but_not_billed") stock_not_billed_account = self.get_company_default("stock_received_but_not_billed")
stock_items = self.get_stock_items() stock_items = self.get_stock_items()
asset_items = [d.is_fixed_asset for d in self.items if d.is_fixed_asset] asset_received_but_not_billed = None
if len(asset_items) > 0:
asset_received_but_not_billed = self.get_company_default("asset_received_but_not_billed")
if self.update_stock: if self.update_stock:
self.validate_item_code() self.validate_item_code()
@@ -357,6 +355,8 @@ class PurchaseInvoice(BuyingController):
) )
item.expense_account = asset_category_account item.expense_account = asset_category_account
elif item.is_fixed_asset and item.pr_detail: elif item.is_fixed_asset and item.pr_detail:
if not asset_received_but_not_billed:
asset_received_but_not_billed = self.get_company_default("asset_received_but_not_billed")
item.expense_account = asset_received_but_not_billed item.expense_account = asset_received_but_not_billed
elif not item.expense_account and for_validate: elif not item.expense_account and for_validate:
throw(_("Expense account is mandatory for item {0}").format(item.item_code or item.item_name)) throw(_("Expense account is mandatory for item {0}").format(item.item_code or item.item_name))
@@ -924,8 +924,9 @@ class PurchaseInvoice(BuyingController):
) )
def get_asset_gl_entry(self, gl_entries): def get_asset_gl_entry(self, gl_entries):
arbnb_account = self.get_company_default("asset_received_but_not_billed") arbnb_account = None
eiiav_account = self.get_company_default("expenses_included_in_asset_valuation") eiiav_account = None
asset_eiiav_currency = None
for item in self.get("items"): for item in self.get("items"):
if item.is_fixed_asset: if item.is_fixed_asset:
@@ -937,6 +938,8 @@ class PurchaseInvoice(BuyingController):
"Asset Received But Not Billed", "Asset Received But Not Billed",
"Fixed Asset", "Fixed Asset",
]: ]:
if not arbnb_account:
arbnb_account = self.get_company_default("asset_received_but_not_billed")
item.expense_account = arbnb_account item.expense_account = arbnb_account
if not self.update_stock: if not self.update_stock:
@@ -959,7 +962,10 @@ class PurchaseInvoice(BuyingController):
) )
if item.item_tax_amount: if item.item_tax_amount:
asset_eiiav_currency = get_account_currency(eiiav_account) if not eiiav_account or not asset_eiiav_currency:
eiiav_account = self.get_company_default("expenses_included_in_asset_valuation")
asset_eiiav_currency = get_account_currency(eiiav_account)
gl_entries.append( gl_entries.append(
self.get_gl_dict( self.get_gl_dict(
{ {
@@ -1002,7 +1008,10 @@ class PurchaseInvoice(BuyingController):
) )
if item.item_tax_amount and not cint(erpnext.is_perpetual_inventory_enabled(self.company)): if item.item_tax_amount and not cint(erpnext.is_perpetual_inventory_enabled(self.company)):
asset_eiiav_currency = get_account_currency(eiiav_account) if not eiiav_account or not asset_eiiav_currency:
eiiav_account = self.get_company_default("expenses_included_in_asset_valuation")
asset_eiiav_currency = get_account_currency(eiiav_account)
gl_entries.append( gl_entries.append(
self.get_gl_dict( self.get_gl_dict(
{ {
@@ -1022,47 +1031,46 @@ class PurchaseInvoice(BuyingController):
) )
) )
# When update stock is checked
# Assets are bought through this document then it will be linked to this document # Assets are bought through this document then it will be linked to this document
if self.update_stock: if flt(item.landed_cost_voucher_amount):
if flt(item.landed_cost_voucher_amount): if not eiiav_account:
gl_entries.append( eiiav_account = self.get_company_default("expenses_included_in_asset_valuation")
self.get_gl_dict(
{
"account": eiiav_account,
"against": cwip_account,
"cost_center": item.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"credit": flt(item.landed_cost_voucher_amount),
"project": item.project or self.project,
},
item=item,
)
)
gl_entries.append( gl_entries.append(
self.get_gl_dict( self.get_gl_dict(
{ {
"account": cwip_account, "account": eiiav_account,
"against": eiiav_account, "against": cwip_account,
"cost_center": item.cost_center, "cost_center": item.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"), "remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"debit": flt(item.landed_cost_voucher_amount), "credit": flt(item.landed_cost_voucher_amount),
"project": item.project or self.project, "project": item.project or self.project,
}, },
item=item, item=item,
)
) )
# update gross amount of assets bought through this document
assets = frappe.db.get_all(
"Asset", filters={"purchase_invoice": self.name, "item_code": item.item_code}
) )
for asset in assets:
frappe.db.set_value("Asset", asset.name, "gross_purchase_amount", flt(item.valuation_rate)) gl_entries.append(
frappe.db.set_value( self.get_gl_dict(
"Asset", asset.name, "purchase_receipt_amount", flt(item.valuation_rate) {
"account": cwip_account,
"against": eiiav_account,
"cost_center": item.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"debit": flt(item.landed_cost_voucher_amount),
"project": item.project or self.project,
},
item=item,
) )
)
# update gross amount of assets bought through this document
assets = frappe.db.get_all(
"Asset", filters={"purchase_invoice": self.name, "item_code": item.item_code}
)
for asset in assets:
frappe.db.set_value("Asset", asset.name, "gross_purchase_amount", flt(item.valuation_rate))
frappe.db.set_value("Asset", asset.name, "purchase_receipt_amount", flt(item.valuation_rate))
return gl_entries return gl_entries

View File

@@ -15,7 +15,6 @@
"posting_date", "posting_date",
"clearance_date", "clearance_date",
"rate_of_interest", "rate_of_interest",
"payroll_payable_account",
"is_term_loan", "is_term_loan",
"repay_from_salary", "repay_from_salary",
"payment_details_section", "payment_details_section",
@@ -41,6 +40,7 @@
"amended_from", "amended_from",
"accounting_details_section", "accounting_details_section",
"payment_account", "payment_account",
"payroll_payable_account",
"penalty_income_account", "penalty_income_account",
"column_break_36", "column_break_36",
"loan_account" "loan_account"
@@ -263,6 +263,7 @@
{ {
"default": "0", "default": "0",
"fetch_from": "against_loan.repay_from_salary", "fetch_from": "against_loan.repay_from_salary",
"fetch_if_empty": 1,
"fieldname": "repay_from_salary", "fieldname": "repay_from_salary",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Repay From Salary" "label": "Repay From Salary"
@@ -280,6 +281,7 @@
"label": "Accounting Details" "label": "Accounting Details"
}, },
{ {
"depends_on": "eval:!doc.repay_from_salary",
"fetch_from": "against_loan.payment_account", "fetch_from": "against_loan.payment_account",
"fetch_if_empty": 1, "fetch_if_empty": 1,
"fieldname": "payment_account", "fieldname": "payment_account",

View File

@@ -377,3 +377,4 @@ execute:frappe.db.set_value("Naming Series", "Naming Series", {"select_doc_for_s
erpnext.patches.v13_0.update_schedule_type_in_loans erpnext.patches.v13_0.update_schedule_type_in_loans
erpnext.patches.v13_0.update_asset_value_for_manual_depr_entries erpnext.patches.v13_0.update_asset_value_for_manual_depr_entries
erpnext.patches.v13_0.update_docs_link erpnext.patches.v13_0.update_docs_link
erpnext.patches.v13_0.correct_asset_value_if_je_with_workflow

View File

@@ -0,0 +1,119 @@
import frappe
from frappe.model.workflow import get_workflow_name
from frappe.query_builder.functions import IfNull, Sum
def execute():
active_je_workflow = get_workflow_name("Journal Entry")
if not active_je_workflow:
return
correct_value_for_assets_with_manual_depr_entries()
finance_books = frappe.db.get_all("Finance Book", pluck="name")
if finance_books:
for fb_name in finance_books:
correct_value_for_assets_with_auto_depr(fb_name)
correct_value_for_assets_with_auto_depr()
def correct_value_for_assets_with_manual_depr_entries():
asset = frappe.qb.DocType("Asset")
gle = frappe.qb.DocType("GL Entry")
aca = frappe.qb.DocType("Asset Category Account")
company = frappe.qb.DocType("Company")
asset_details_and_depr_amount_map = (
frappe.qb.from_(gle)
.join(asset)
.on(gle.against_voucher == asset.name)
.join(aca)
.on((aca.parent == asset.asset_category) & (aca.company_name == asset.company))
.join(company)
.on(company.name == asset.company)
.select(
asset.name.as_("asset_name"),
asset.gross_purchase_amount.as_("gross_purchase_amount"),
asset.opening_accumulated_depreciation.as_("opening_accumulated_depreciation"),
Sum(gle.debit).as_("depr_amount"),
)
.where(
gle.account == IfNull(aca.depreciation_expense_account, company.depreciation_expense_account)
)
.where(gle.debit != 0)
.where(gle.is_cancelled == 0)
.where(asset.docstatus == 1)
.where(asset.calculate_depreciation == 0)
.groupby(asset.name)
)
frappe.qb.update(asset).join(asset_details_and_depr_amount_map).on(
asset_details_and_depr_amount_map.asset_name == asset.name
).set(
asset.value_after_depreciation,
asset_details_and_depr_amount_map.gross_purchase_amount
- asset_details_and_depr_amount_map.opening_accumulated_depreciation
- asset_details_and_depr_amount_map.depr_amount,
).run()
def correct_value_for_assets_with_auto_depr(fb_name=None):
asset = frappe.qb.DocType("Asset")
gle = frappe.qb.DocType("GL Entry")
aca = frappe.qb.DocType("Asset Category Account")
company = frappe.qb.DocType("Company")
afb = frappe.qb.DocType("Asset Finance Book")
asset_details_and_depr_amount_map = (
frappe.qb.from_(gle)
.join(asset)
.on(gle.against_voucher == asset.name)
.join(aca)
.on((aca.parent == asset.asset_category) & (aca.company_name == asset.company))
.join(company)
.on(company.name == asset.company)
.select(
asset.name.as_("asset_name"),
asset.gross_purchase_amount.as_("gross_purchase_amount"),
asset.opening_accumulated_depreciation.as_("opening_accumulated_depreciation"),
Sum(gle.debit).as_("depr_amount"),
)
.where(
gle.account == IfNull(aca.depreciation_expense_account, company.depreciation_expense_account)
)
.where(gle.debit != 0)
.where(gle.is_cancelled == 0)
.where(asset.docstatus == 1)
.where(asset.calculate_depreciation == 1)
.groupby(asset.name)
)
if fb_name:
asset_details_and_depr_amount_map = asset_details_and_depr_amount_map.where(
gle.finance_book == fb_name
)
else:
asset_details_and_depr_amount_map = asset_details_and_depr_amount_map.where(
(gle.finance_book.isin([""])) | (gle.finance_book.isnull())
)
query = (
frappe.qb.update(afb)
.join(asset_details_and_depr_amount_map)
.on(asset_details_and_depr_amount_map.asset_name == afb.parent)
.set(
afb.value_after_depreciation,
asset_details_and_depr_amount_map.gross_purchase_amount
- asset_details_and_depr_amount_map.opening_accumulated_depreciation
- asset_details_and_depr_amount_map.depr_amount,
)
)
if fb_name:
query = query.where(afb.finance_book == fb_name)
else:
query = query.where((afb.finance_book.isin([""])) | (afb.finance_book.isnull()))
query.run()