fix: Accounting dimensions for child tables
This commit is contained in:
parent
d0a1ed9017
commit
3d11ac0e75
@ -509,7 +509,7 @@ class JournalEntry(AccountsController):
|
|||||||
"cost_center": d.cost_center,
|
"cost_center": d.cost_center,
|
||||||
"project": d.project,
|
"project": d.project,
|
||||||
"finance_book": self.finance_book
|
"finance_book": self.finance_book
|
||||||
})
|
}, item=d)
|
||||||
)
|
)
|
||||||
|
|
||||||
if gl_map:
|
if gl_map:
|
||||||
|
|||||||
@ -507,7 +507,7 @@ class PaymentEntry(AccountsController):
|
|||||||
"debit_in_account_currency": d.amount,
|
"debit_in_account_currency": d.amount,
|
||||||
"debit": d.amount,
|
"debit": d.amount,
|
||||||
"cost_center": d.cost_center
|
"cost_center": d.cost_center
|
||||||
})
|
}, item=d)
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_advance_paid(self):
|
def update_advance_paid(self):
|
||||||
|
|||||||
@ -454,7 +454,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||||
"cost_center": item.cost_center,
|
"cost_center": item.cost_center,
|
||||||
"project": item.project
|
"project": item.project
|
||||||
}, account_currency)
|
}, account_currency, item=item)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Amount added through landed-cost-voucher
|
# Amount added through landed-cost-voucher
|
||||||
@ -466,7 +466,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||||
"credit": flt(item.landed_cost_voucher_amount),
|
"credit": flt(item.landed_cost_voucher_amount),
|
||||||
"project": item.project
|
"project": item.project
|
||||||
}))
|
}), item=item)
|
||||||
|
|
||||||
# sub-contracting warehouse
|
# sub-contracting warehouse
|
||||||
if flt(item.rm_supp_cost):
|
if flt(item.rm_supp_cost):
|
||||||
@ -480,7 +480,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
"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"),
|
||||||
"credit": flt(item.rm_supp_cost)
|
"credit": flt(item.rm_supp_cost)
|
||||||
}, warehouse_account[self.supplier_warehouse]["account_currency"]))
|
}, warehouse_account[self.supplier_warehouse]["account_currency"], item=item))
|
||||||
elif not item.is_fixed_asset or (item.is_fixed_asset and is_cwip_accounting_disabled()):
|
elif not item.is_fixed_asset or (item.is_fixed_asset and is_cwip_accounting_disabled()):
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
self.get_gl_dict({
|
self.get_gl_dict({
|
||||||
@ -492,7 +492,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
else flt(item.net_amount, item.precision("net_amount"))),
|
else flt(item.net_amount, item.precision("net_amount"))),
|
||||||
"cost_center": item.cost_center,
|
"cost_center": item.cost_center,
|
||||||
"project": item.project
|
"project": item.project
|
||||||
}, account_currency)
|
}, account_currency, item=item)
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.auto_accounting_for_stock and self.is_opening == "No" and \
|
if self.auto_accounting_for_stock and self.is_opening == "No" and \
|
||||||
@ -511,7 +511,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
"debit": flt(item.item_tax_amount, item.precision("item_tax_amount")),
|
"debit": flt(item.item_tax_amount, item.precision("item_tax_amount")),
|
||||||
"remarks": self.remarks or "Accounting Entry for Stock",
|
"remarks": self.remarks or "Accounting Entry for Stock",
|
||||||
"cost_center": self.cost_center
|
"cost_center": self.cost_center
|
||||||
})
|
}, item=item)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.negative_expense_to_be_booked += flt(item.item_tax_amount, \
|
self.negative_expense_to_be_booked += flt(item.item_tax_amount, \
|
||||||
@ -540,7 +540,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
"debit_in_account_currency": (base_asset_amount
|
"debit_in_account_currency": (base_asset_amount
|
||||||
if asset_rbnb_currency == self.company_currency else asset_amount),
|
if asset_rbnb_currency == self.company_currency else asset_amount),
|
||||||
"cost_center": item.cost_center
|
"cost_center": item.cost_center
|
||||||
}))
|
}, item=item))
|
||||||
|
|
||||||
if item.item_tax_amount:
|
if item.item_tax_amount:
|
||||||
asset_eiiav_currency = get_account_currency(eiiav_account)
|
asset_eiiav_currency = get_account_currency(eiiav_account)
|
||||||
@ -553,7 +553,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
"credit_in_account_currency": (item.item_tax_amount
|
"credit_in_account_currency": (item.item_tax_amount
|
||||||
if asset_eiiav_currency == self.company_currency else
|
if asset_eiiav_currency == self.company_currency else
|
||||||
item.item_tax_amount / self.conversion_rate)
|
item.item_tax_amount / self.conversion_rate)
|
||||||
}))
|
}, item=item))
|
||||||
else:
|
else:
|
||||||
cwip_account = get_asset_account("capital_work_in_progress_account",
|
cwip_account = get_asset_account("capital_work_in_progress_account",
|
||||||
item.asset, company = self.company)
|
item.asset, company = self.company)
|
||||||
@ -567,7 +567,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
"debit_in_account_currency": (base_asset_amount
|
"debit_in_account_currency": (base_asset_amount
|
||||||
if cwip_account_currency == self.company_currency else asset_amount),
|
if cwip_account_currency == self.company_currency else asset_amount),
|
||||||
"cost_center": self.cost_center
|
"cost_center": self.cost_center
|
||||||
}))
|
}, item=item))
|
||||||
|
|
||||||
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)
|
asset_eiiav_currency = get_account_currency(eiiav_account)
|
||||||
@ -580,7 +580,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
"credit_in_account_currency": (item.item_tax_amount
|
"credit_in_account_currency": (item.item_tax_amount
|
||||||
if asset_eiiav_currency == self.company_currency else
|
if asset_eiiav_currency == self.company_currency else
|
||||||
item.item_tax_amount / self.conversion_rate)
|
item.item_tax_amount / self.conversion_rate)
|
||||||
}))
|
}, item=item))
|
||||||
|
|
||||||
return gl_entries
|
return gl_entries
|
||||||
|
|
||||||
@ -607,7 +607,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
"remarks": self.get("remarks") or _("Stock Adjustment"),
|
"remarks": self.get("remarks") or _("Stock Adjustment"),
|
||||||
"cost_center": item.cost_center,
|
"cost_center": item.cost_center,
|
||||||
"project": item.project
|
"project": item.project
|
||||||
}, account_currency)
|
}, account_currency, item=item)
|
||||||
)
|
)
|
||||||
|
|
||||||
warehouse_debit_amount = stock_amount
|
warehouse_debit_amount = stock_amount
|
||||||
|
|||||||
@ -784,7 +784,7 @@ class SalesInvoice(SellingController):
|
|||||||
if account_currency==self.company_currency
|
if account_currency==self.company_currency
|
||||||
else flt(item.net_amount, item.precision("net_amount"))),
|
else flt(item.net_amount, item.precision("net_amount"))),
|
||||||
"cost_center": item.cost_center
|
"cost_center": item.cost_center
|
||||||
}, account_currency)
|
}, account_currency, item=item)
|
||||||
)
|
)
|
||||||
|
|
||||||
# expense account gl entries
|
# expense account gl entries
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from frappe.utils import flt, cstr, cint
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.meta import get_field_precision
|
from frappe.model.meta import get_field_precision
|
||||||
from erpnext.accounts.doctype.budget.budget import validate_expense_against_budget
|
from erpnext.accounts.doctype.budget.budget import validate_expense_against_budget
|
||||||
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
|
||||||
|
|
||||||
|
|
||||||
class StockAccountInvalidTransaction(frappe.ValidationError): pass
|
class StockAccountInvalidTransaction(frappe.ValidationError): pass
|
||||||
@ -49,10 +50,11 @@ def process_gl_map(gl_map, merge_entries=True):
|
|||||||
|
|
||||||
def merge_similar_entries(gl_map):
|
def merge_similar_entries(gl_map):
|
||||||
merged_gl_map = []
|
merged_gl_map = []
|
||||||
|
accounting_dimensions = get_accounting_dimensions()
|
||||||
for entry in gl_map:
|
for entry in gl_map:
|
||||||
# if there is already an entry in this account then just add it
|
# if there is already an entry in this account then just add it
|
||||||
# to that entry
|
# to that entry
|
||||||
same_head = check_if_in_list(entry, merged_gl_map)
|
same_head = check_if_in_list(entry, merged_gl_map, accounting_dimensions)
|
||||||
if same_head:
|
if same_head:
|
||||||
same_head.debit = flt(same_head.debit) + flt(entry.debit)
|
same_head.debit = flt(same_head.debit) + flt(entry.debit)
|
||||||
same_head.debit_in_account_currency = \
|
same_head.debit_in_account_currency = \
|
||||||
@ -69,15 +71,23 @@ def merge_similar_entries(gl_map):
|
|||||||
|
|
||||||
return merged_gl_map
|
return merged_gl_map
|
||||||
|
|
||||||
def check_if_in_list(gle, gl_map):
|
def check_if_in_list(gle, gl_map, dimensions=None):
|
||||||
|
account_head_fieldnames = ['party_type', 'party', 'against_voucher', 'against_voucher_type',
|
||||||
|
'cost_center', 'project']
|
||||||
|
|
||||||
|
if dimensions:
|
||||||
|
account_head_fieldnames = account_head_fieldnames + dimensions
|
||||||
|
|
||||||
for e in gl_map:
|
for e in gl_map:
|
||||||
if e.account == gle.account \
|
same_head = True
|
||||||
and cstr(e.get('party_type'))==cstr(gle.get('party_type')) \
|
if e.account != gle.account:
|
||||||
and cstr(e.get('party'))==cstr(gle.get('party')) \
|
same_head = False
|
||||||
and cstr(e.get('against_voucher'))==cstr(gle.get('against_voucher')) \
|
|
||||||
and cstr(e.get('against_voucher_type')) == cstr(gle.get('against_voucher_type')) \
|
for fieldname in account_head_fieldnames:
|
||||||
and cstr(e.get('cost_center')) == cstr(gle.get('cost_center')) \
|
if cstr(e.get(fieldname)) != cstr(gle.get(fieldname)):
|
||||||
and cstr(e.get('project')) == cstr(gle.get('project')):
|
same_head = False
|
||||||
|
|
||||||
|
if same_head:
|
||||||
return e
|
return e
|
||||||
|
|
||||||
def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False):
|
def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False):
|
||||||
|
|||||||
@ -339,7 +339,7 @@ class AccountsController(TransactionBase):
|
|||||||
frappe.throw(_("Row #{0}: Account {1} does not belong to company {2}")
|
frappe.throw(_("Row #{0}: Account {1} does not belong to company {2}")
|
||||||
.format(d.idx, d.account_head, self.company))
|
.format(d.idx, d.account_head, self.company))
|
||||||
|
|
||||||
def get_gl_dict(self, args, account_currency=None):
|
def get_gl_dict(self, args, account_currency=None, item=None):
|
||||||
"""this method populates the common properties of a gl entry record"""
|
"""this method populates the common properties of a gl entry record"""
|
||||||
|
|
||||||
posting_date = args.get('posting_date') or self.get('posting_date')
|
posting_date = args.get('posting_date') or self.get('posting_date')
|
||||||
@ -372,6 +372,8 @@ class AccountsController(TransactionBase):
|
|||||||
|
|
||||||
for dimension in accounting_dimensions:
|
for dimension in accounting_dimensions:
|
||||||
dimension_dict[dimension] = self.get(dimension)
|
dimension_dict[dimension] = self.get(dimension)
|
||||||
|
if item and item.get(dimension):
|
||||||
|
dimension_dict[dimension] = item.get(dimension)
|
||||||
|
|
||||||
gl_dict.update(dimension_dict)
|
gl_dict.update(dimension_dict)
|
||||||
gl_dict.update(args)
|
gl_dict.update(args)
|
||||||
|
|||||||
@ -80,7 +80,7 @@ class StockController(AccountsController):
|
|||||||
"cost_center": item_row.cost_center,
|
"cost_center": item_row.cost_center,
|
||||||
"remarks": self.get("remarks") or "Accounting Entry for Stock",
|
"remarks": self.get("remarks") or "Accounting Entry for Stock",
|
||||||
"debit": flt(sle.stock_value_difference, 2),
|
"debit": flt(sle.stock_value_difference, 2),
|
||||||
}, warehouse_account[sle.warehouse]["account_currency"]))
|
}, warehouse_account[sle.warehouse]["account_currency"], item=item_row))
|
||||||
|
|
||||||
# to target warehouse / expense account
|
# to target warehouse / expense account
|
||||||
gl_list.append(self.get_gl_dict({
|
gl_list.append(self.get_gl_dict({
|
||||||
@ -90,7 +90,7 @@ class StockController(AccountsController):
|
|||||||
"remarks": self.get("remarks") or "Accounting Entry for Stock",
|
"remarks": self.get("remarks") or "Accounting Entry for Stock",
|
||||||
"credit": flt(sle.stock_value_difference, 2),
|
"credit": flt(sle.stock_value_difference, 2),
|
||||||
"project": item_row.get("project") or self.get("project")
|
"project": item_row.get("project") or self.get("project")
|
||||||
}))
|
}, item=item_row))
|
||||||
elif sle.warehouse not in warehouse_with_no_account:
|
elif sle.warehouse not in warehouse_with_no_account:
|
||||||
warehouse_with_no_account.append(sle.warehouse)
|
warehouse_with_no_account.append(sle.warehouse)
|
||||||
|
|
||||||
|
|||||||
@ -206,7 +206,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
"cost_center": d.cost_center,
|
"cost_center": d.cost_center,
|
||||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||||
"debit": stock_value_diff
|
"debit": stock_value_diff
|
||||||
}, warehouse_account[d.warehouse]["account_currency"]))
|
}, warehouse_account[d.warehouse]["account_currency"], item=d))
|
||||||
|
|
||||||
# stock received but not billed
|
# stock received but not billed
|
||||||
stock_rbnb_currency = get_account_currency(stock_rbnb)
|
stock_rbnb_currency = get_account_currency(stock_rbnb)
|
||||||
@ -218,7 +218,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
"credit": flt(d.base_net_amount, d.precision("base_net_amount")),
|
"credit": flt(d.base_net_amount, d.precision("base_net_amount")),
|
||||||
"credit_in_account_currency": flt(d.base_net_amount, d.precision("base_net_amount")) \
|
"credit_in_account_currency": flt(d.base_net_amount, d.precision("base_net_amount")) \
|
||||||
if stock_rbnb_currency==self.company_currency else flt(d.net_amount, d.precision("net_amount"))
|
if stock_rbnb_currency==self.company_currency else flt(d.net_amount, d.precision("net_amount"))
|
||||||
}, stock_rbnb_currency))
|
}, stock_rbnb_currency, item=d))
|
||||||
|
|
||||||
negative_expense_to_be_booked += flt(d.item_tax_amount)
|
negative_expense_to_be_booked += flt(d.item_tax_amount)
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||||
"credit": flt(d.landed_cost_voucher_amount),
|
"credit": flt(d.landed_cost_voucher_amount),
|
||||||
"project": d.project
|
"project": d.project
|
||||||
}))
|
}, item=d))
|
||||||
|
|
||||||
# sub-contracting warehouse
|
# sub-contracting warehouse
|
||||||
if flt(d.rm_supp_cost) and warehouse_account.get(self.supplier_warehouse):
|
if flt(d.rm_supp_cost) and warehouse_account.get(self.supplier_warehouse):
|
||||||
@ -241,7 +241,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
"cost_center": d.cost_center,
|
"cost_center": d.cost_center,
|
||||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||||
"credit": flt(d.rm_supp_cost)
|
"credit": flt(d.rm_supp_cost)
|
||||||
}, warehouse_account[self.supplier_warehouse]["account_currency"]))
|
}, warehouse_account[self.supplier_warehouse]["account_currency"], item=d))
|
||||||
|
|
||||||
# divisional loss adjustment
|
# divisional loss adjustment
|
||||||
valuation_amount_as_per_doc = flt(d.base_net_amount, d.precision("base_net_amount")) + \
|
valuation_amount_as_per_doc = flt(d.base_net_amount, d.precision("base_net_amount")) + \
|
||||||
@ -263,7 +263,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||||
"debit": divisional_loss,
|
"debit": divisional_loss,
|
||||||
"project": d.project
|
"project": d.project
|
||||||
}, stock_rbnb_currency))
|
}, stock_rbnb_currency, item=d))
|
||||||
|
|
||||||
elif d.warehouse not in warehouse_with_no_account or \
|
elif d.warehouse not in warehouse_with_no_account or \
|
||||||
d.rejected_warehouse not in warehouse_with_no_account:
|
d.rejected_warehouse not in warehouse_with_no_account:
|
||||||
@ -345,7 +345,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
"debit": base_asset_amount,
|
"debit": base_asset_amount,
|
||||||
"debit_in_account_currency": (base_asset_amount
|
"debit_in_account_currency": (base_asset_amount
|
||||||
if cwip_account_currency == self.company_currency else asset_amount)
|
if cwip_account_currency == self.company_currency else asset_amount)
|
||||||
}))
|
}, item=d))
|
||||||
|
|
||||||
# Asset received but not billed
|
# Asset received but not billed
|
||||||
asset_rbnb_currency = get_account_currency(arbnb_account)
|
asset_rbnb_currency = get_account_currency(arbnb_account)
|
||||||
@ -357,7 +357,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
"credit": base_asset_amount,
|
"credit": base_asset_amount,
|
||||||
"credit_in_account_currency": (base_asset_amount
|
"credit_in_account_currency": (base_asset_amount
|
||||||
if asset_rbnb_currency == self.company_currency else asset_amount)
|
if asset_rbnb_currency == self.company_currency else asset_amount)
|
||||||
}))
|
}, item=d))
|
||||||
|
|
||||||
return gl_entries
|
return gl_entries
|
||||||
|
|
||||||
|
|||||||
@ -611,7 +611,7 @@ class StockEntry(StockController):
|
|||||||
"cost_center": d.cost_center,
|
"cost_center": d.cost_center,
|
||||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||||
"credit": additional_cost
|
"credit": additional_cost
|
||||||
}))
|
}, item=d))
|
||||||
|
|
||||||
gl_entries.append(self.get_gl_dict({
|
gl_entries.append(self.get_gl_dict({
|
||||||
"account": d.expense_account,
|
"account": d.expense_account,
|
||||||
@ -619,7 +619,7 @@ class StockEntry(StockController):
|
|||||||
"cost_center": d.cost_center,
|
"cost_center": d.cost_center,
|
||||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||||
"credit": -1 * additional_cost # put it as negative credit instead of debit purposefully
|
"credit": -1 * additional_cost # put it as negative credit instead of debit purposefully
|
||||||
}))
|
}, item=d))
|
||||||
|
|
||||||
return gl_entries
|
return gl_entries
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user