fix: Allow creation of multiple landed cost voucher against a Purchase Document (#20058)
This commit is contained in:
parent
5af4c57ef7
commit
55bc26e300
@ -88,7 +88,7 @@ class PurchaseReceipt(BuyingController):
|
||||
|
||||
if getdate(self.posting_date) > getdate(nowdate()):
|
||||
throw(_("Posting Date cannot be future date"))
|
||||
|
||||
|
||||
def validate_cwip_accounts(self):
|
||||
for item in self.get('items'):
|
||||
if item.is_fixed_asset and is_cwip_accounting_enabled(item.asset_category):
|
||||
@ -362,7 +362,7 @@ class PurchaseReceipt(BuyingController):
|
||||
# valuation rate is total of net rate, raw mat supp cost, tax amount, lcv amount per item
|
||||
self.update_assets(item, item.valuation_rate)
|
||||
return gl_entries
|
||||
|
||||
|
||||
def add_asset_gl_entries(self, item, gl_entries):
|
||||
arbnb_account = self.get_company_default("asset_received_but_not_billed")
|
||||
# This returns category's cwip account if not then fallback to company's default cwip account
|
||||
@ -395,7 +395,7 @@ class PurchaseReceipt(BuyingController):
|
||||
"credit_in_account_currency": (base_asset_amount
|
||||
if asset_rbnb_currency == self.company_currency else asset_amount)
|
||||
}, item=item))
|
||||
|
||||
|
||||
def add_lcv_gl_entries(self, item, gl_entries):
|
||||
expenses_included_in_asset_valuation = self.get_company_default("expenses_included_in_asset_valuation")
|
||||
if not is_cwip_accounting_enabled(item.asset_category):
|
||||
@ -404,7 +404,7 @@ class PurchaseReceipt(BuyingController):
|
||||
else:
|
||||
# This returns company's default cwip account
|
||||
asset_account = get_asset_account("capital_work_in_progress_account", company=self.company)
|
||||
|
||||
|
||||
gl_entries.append(self.get_gl_dict({
|
||||
"account": expenses_included_in_asset_valuation,
|
||||
"against": asset_account,
|
||||
@ -424,7 +424,7 @@ class PurchaseReceipt(BuyingController):
|
||||
}, item=item))
|
||||
|
||||
def update_assets(self, item, valuation_rate):
|
||||
assets = frappe.db.get_all('Asset',
|
||||
assets = frappe.db.get_all('Asset',
|
||||
filters={ 'purchase_receipt': self.name, 'item_code': item.item_code }
|
||||
)
|
||||
|
||||
@ -610,27 +610,36 @@ def make_stock_entry(source_name,target_doc=None):
|
||||
return doclist
|
||||
|
||||
def get_item_account_wise_additional_cost(purchase_document):
|
||||
landed_cost_voucher = frappe.get_value("Landed Cost Purchase Receipt",
|
||||
{"receipt_document": purchase_document, "docstatus": 1}, "parent")
|
||||
landed_cost_vouchers = frappe.get_all("Landed Cost Purchase Receipt", fields=["parent"],
|
||||
filters = {"receipt_document": purchase_document, "docstatus": 1})
|
||||
|
||||
if not landed_cost_voucher:
|
||||
if not landed_cost_vouchers:
|
||||
return
|
||||
|
||||
total_item_cost = 0
|
||||
item_account_wise_cost = {}
|
||||
landed_cost_voucher_doc = frappe.get_doc("Landed Cost Voucher", landed_cost_voucher)
|
||||
based_on_field = frappe.scrub(landed_cost_voucher_doc.distribute_charges_based_on)
|
||||
item_cost_allocated = []
|
||||
|
||||
for item in landed_cost_voucher_doc.items:
|
||||
total_item_cost += item.get(based_on_field)
|
||||
for lcv in landed_cost_vouchers:
|
||||
landed_cost_voucher_doc = frappe.get_cached_doc("Landed Cost Voucher", lcv.parent)
|
||||
based_on_field = frappe.scrub(landed_cost_voucher_doc.distribute_charges_based_on)
|
||||
|
||||
for item in landed_cost_voucher_doc.items:
|
||||
if item.receipt_document == purchase_document:
|
||||
for account in landed_cost_voucher_doc.taxes:
|
||||
item_account_wise_cost.setdefault((item.item_code, item.purchase_receipt_item), {})
|
||||
item_account_wise_cost[(item.item_code, item.purchase_receipt_item)].setdefault(account.expense_account, 0.0)
|
||||
item_account_wise_cost[(item.item_code, item.purchase_receipt_item)][account.expense_account] += \
|
||||
account.amount * item.get(based_on_field) / total_item_cost
|
||||
for item in landed_cost_voucher_doc.items:
|
||||
if item.purchase_receipt_item not in item_cost_allocated:
|
||||
total_item_cost += item.get(based_on_field)
|
||||
item_cost_allocated.append(item.purchase_receipt_item)
|
||||
|
||||
for lcv in landed_cost_vouchers:
|
||||
landed_cost_voucher_doc = frappe.get_cached_doc("Landed Cost Voucher", lcv.parent)
|
||||
based_on_field = frappe.scrub(landed_cost_voucher_doc.distribute_charges_based_on)
|
||||
|
||||
for item in landed_cost_voucher_doc.items:
|
||||
if item.receipt_document == purchase_document:
|
||||
for account in landed_cost_voucher_doc.taxes:
|
||||
item_account_wise_cost.setdefault((item.item_code, item.purchase_receipt_item), {})
|
||||
item_account_wise_cost[(item.item_code, item.purchase_receipt_item)].setdefault(account.expense_account, 0.0)
|
||||
item_account_wise_cost[(item.item_code, item.purchase_receipt_item)][account.expense_account] += \
|
||||
account.amount * item.get(based_on_field) / total_item_cost
|
||||
|
||||
return item_account_wise_cost
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user