Merge pull request #39276 from frappe/mergify/bp/version-15-hotfix/pr-39238
fix: Set asset purchase amount based on qty and valuation_rate (backport #39238)
This commit is contained in:
commit
24cfcf36e4
@ -1084,17 +1084,6 @@ class PurchaseInvoice(BuyingController):
|
|||||||
item=item,
|
item=item,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# update gross amount of asset 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)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
self.auto_accounting_for_stock
|
self.auto_accounting_for_stock
|
||||||
and self.is_opening == "No"
|
and self.is_opening == "No"
|
||||||
@ -1134,17 +1123,24 @@ class PurchaseInvoice(BuyingController):
|
|||||||
item.item_tax_amount, item.precision("item_tax_amount")
|
item.item_tax_amount, item.precision("item_tax_amount")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if item.is_fixed_asset and item.landed_cost_voucher_amount:
|
||||||
|
self.update_gross_purchase_amount_for_linked_assets(item)
|
||||||
|
|
||||||
|
def update_gross_purchase_amount_for_linked_assets(self, item):
|
||||||
assets = frappe.db.get_all(
|
assets = frappe.db.get_all(
|
||||||
"Asset",
|
"Asset",
|
||||||
filters={"purchase_invoice": self.name, "item_code": item.item_code},
|
filters={"purchase_invoice": self.name, "item_code": item.item_code},
|
||||||
fields=["name", "asset_quantity"],
|
fields=["name", "asset_quantity"],
|
||||||
)
|
)
|
||||||
for asset in assets:
|
for asset in assets:
|
||||||
|
purchase_amount = flt(item.valuation_rate) * asset.asset_quantity
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
"Asset", asset.name, "gross_purchase_amount", flt(item.valuation_rate) * asset.asset_quantity
|
"Asset",
|
||||||
)
|
asset.name,
|
||||||
frappe.db.set_value(
|
{
|
||||||
"Asset", asset.name, "purchase_receipt_amount", flt(item.valuation_rate) * asset.asset_quantity
|
"gross_purchase_amount": purchase_amount,
|
||||||
|
"purchase_receipt_amount": purchase_amount,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
def make_stock_adjustment_entry(
|
def make_stock_adjustment_entry(
|
||||||
|
@ -571,10 +571,16 @@ frappe.ui.form.on('Asset', {
|
|||||||
indicator: 'red'
|
indicator: 'red'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
frm.set_value('gross_purchase_amount', item.base_net_rate + item.item_tax_amount);
|
var is_grouped_asset = frappe.db.get_value('Item', item.item_code, 'is_grouped_asset');
|
||||||
frm.set_value('purchase_receipt_amount', item.base_net_rate + item.item_tax_amount);
|
var asset_quantity = is_grouped_asset ? item.qty : 1;
|
||||||
item.asset_location && frm.set_value('location', item.asset_location);
|
var purchase_amount = flt(item.valuation_rate * asset_quantity, precision('gross_purchase_amount'));
|
||||||
|
|
||||||
|
frm.set_value('gross_purchase_amount', purchase_amount);
|
||||||
|
frm.set_value('purchase_receipt_amount', purchase_amount);
|
||||||
|
frm.set_value('asset_quantity', asset_quantity);
|
||||||
frm.set_value('cost_center', item.cost_center || purchase_doc.cost_center);
|
frm.set_value('cost_center', item.cost_center || purchase_doc.cost_center);
|
||||||
|
if(item.asset_location) { frm.set_value('location', item.asset_location); }
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
set_depreciation_rate: function(frm, row) {
|
set_depreciation_rate: function(frm, row) {
|
||||||
|
@ -744,11 +744,8 @@ class BuyingController(SubcontractingController):
|
|||||||
item_data = frappe.db.get_value(
|
item_data = frappe.db.get_value(
|
||||||
"Item", row.item_code, ["asset_naming_series", "asset_category"], as_dict=1
|
"Item", row.item_code, ["asset_naming_series", "asset_category"], as_dict=1
|
||||||
)
|
)
|
||||||
|
asset_quantity = row.qty if is_grouped_asset else 1
|
||||||
if is_grouped_asset:
|
purchase_amount = flt(row.valuation_rate) * asset_quantity
|
||||||
purchase_amount = flt(row.base_amount + row.item_tax_amount)
|
|
||||||
else:
|
|
||||||
purchase_amount = flt(row.base_rate + row.item_tax_amount)
|
|
||||||
|
|
||||||
asset = frappe.get_doc(
|
asset = frappe.get_doc(
|
||||||
{
|
{
|
||||||
@ -764,7 +761,7 @@ class BuyingController(SubcontractingController):
|
|||||||
"calculate_depreciation": 0,
|
"calculate_depreciation": 0,
|
||||||
"purchase_receipt_amount": purchase_amount,
|
"purchase_receipt_amount": purchase_amount,
|
||||||
"gross_purchase_amount": purchase_amount,
|
"gross_purchase_amount": purchase_amount,
|
||||||
"asset_quantity": row.qty if is_grouped_asset else 1,
|
"asset_quantity": asset_quantity,
|
||||||
"purchase_receipt": self.name if self.doctype == "Purchase Receipt" else None,
|
"purchase_receipt": self.name if self.doctype == "Purchase Receipt" else None,
|
||||||
"purchase_invoice": self.name if self.doctype == "Purchase Invoice" else None,
|
"purchase_invoice": self.name if self.doctype == "Purchase Invoice" else None,
|
||||||
}
|
}
|
||||||
|
@ -717,7 +717,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
):
|
):
|
||||||
warehouse_with_no_account.append(d.warehouse or d.rejected_warehouse)
|
warehouse_with_no_account.append(d.warehouse or d.rejected_warehouse)
|
||||||
|
|
||||||
if d.is_fixed_asset:
|
if d.is_fixed_asset and d.landed_cost_voucher_amount:
|
||||||
self.update_assets(d, d.valuation_rate)
|
self.update_assets(d, d.valuation_rate)
|
||||||
|
|
||||||
if warehouse_with_no_account:
|
if warehouse_with_no_account:
|
||||||
@ -849,11 +849,14 @@ class PurchaseReceipt(BuyingController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for asset in assets:
|
for asset in assets:
|
||||||
|
purchase_amount = flt(valuation_rate) * asset.asset_quantity
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
"Asset", asset.name, "gross_purchase_amount", flt(valuation_rate) * asset.asset_quantity
|
"Asset",
|
||||||
)
|
asset.name,
|
||||||
frappe.db.set_value(
|
{
|
||||||
"Asset", asset.name, "purchase_receipt_amount", flt(valuation_rate) * asset.asset_quantity
|
"gross_purchase_amount": purchase_amount,
|
||||||
|
"purchase_receipt_amount": purchase_amount,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_status(self, status):
|
def update_status(self, status):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user