mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-05 06:28:29 +00:00
fix(asset): handle same asset being sold in multiple line items in sales invoice
(cherry picked from commit 23b094f151)
This commit is contained in:
@@ -1205,6 +1205,13 @@ class SalesInvoice(SellingController):
|
|||||||
def split_asset_based_on_sale_qty(self):
|
def split_asset_based_on_sale_qty(self):
|
||||||
asset_qty_map = self.get_asset_qty()
|
asset_qty_map = self.get_asset_qty()
|
||||||
for asset, qty in asset_qty_map.items():
|
for asset, qty in asset_qty_map.items():
|
||||||
|
if qty["actual_qty"] < qty["sale_qty"]:
|
||||||
|
frappe.throw(
|
||||||
|
_(
|
||||||
|
"Sell quantity cannot exceed the asset quantity. Asset {0} has only {1} item(s)."
|
||||||
|
).format(asset, qty["actual_qty"])
|
||||||
|
)
|
||||||
|
|
||||||
remaining_qty = qty["actual_qty"] - qty["sale_qty"]
|
remaining_qty = qty["actual_qty"] - qty["sale_qty"]
|
||||||
if remaining_qty > 0:
|
if remaining_qty > 0:
|
||||||
split_asset(asset, remaining_qty)
|
split_asset(asset, remaining_qty)
|
||||||
@@ -1227,13 +1234,16 @@ class SalesInvoice(SellingController):
|
|||||||
for row in self.items:
|
for row in self.items:
|
||||||
if row.is_fixed_asset and row.asset:
|
if row.is_fixed_asset and row.asset:
|
||||||
actual_qty = asset_actual_qty.get(row.asset)
|
actual_qty = asset_actual_qty.get(row.asset)
|
||||||
asset_qty_map.setdefault(
|
if row.asset in asset_qty_map.keys():
|
||||||
row.asset,
|
asset_qty_map[row.asset]["sale_qty"] += flt(row.qty)
|
||||||
{
|
else:
|
||||||
"sale_qty": flt(row.qty),
|
asset_qty_map.setdefault(
|
||||||
"actual_qty": flt(actual_qty),
|
row.asset,
|
||||||
},
|
{
|
||||||
)
|
"sale_qty": flt(row.qty),
|
||||||
|
"actual_qty": flt(actual_qty),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
return asset_qty_map
|
return asset_qty_map
|
||||||
|
|
||||||
|
|||||||
@@ -591,7 +591,7 @@ frappe.ui.form.on("Asset", {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const dialog = new frappe.ui.Dialog({
|
let dialog = new frappe.ui.Dialog({
|
||||||
title: __("Sell Asset"),
|
title: __("Sell Asset"),
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
@@ -606,18 +606,30 @@ frappe.ui.form.on("Asset", {
|
|||||||
dialog.set_primary_action(__("Sell"), function () {
|
dialog.set_primary_action(__("Sell"), function () {
|
||||||
const dialog_data = dialog.get_values();
|
const dialog_data = dialog.get_values();
|
||||||
const sell_qty = cint(dialog_data.sell_qty);
|
const sell_qty = cint(dialog_data.sell_qty);
|
||||||
|
const asset_qty = cint(frm.doc.asset_quantity);
|
||||||
|
|
||||||
if (sell_qty < cint(frm.doc.asset_quantity)) {
|
if (sell_qty <= 0) {
|
||||||
frappe.confirm(
|
frappe.throw(__("Sell quantity must be greater than zero"));
|
||||||
__(
|
|
||||||
"The sell quantity is less than the total asset quantity. The remaining quantity will be split into a new asset. This action cannot be undone. <br><b>Do you want to continue?<b>"
|
|
||||||
),
|
|
||||||
() => make_sales_invoice(sell_qty)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
make_sales_invoice(sell_qty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sell_qty > asset_qty) {
|
||||||
|
frappe.throw(__("Sell quantity cannot exceed the asset quantity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sell_qty < asset_qty) {
|
||||||
|
frappe.confirm(
|
||||||
|
__(
|
||||||
|
"The sell quantity is less than the total asset quantity. The remaining quantity will be split into a new asset. This action cannot be undone. <br><br><b>Do you want to continue?</b>"
|
||||||
|
),
|
||||||
|
() => {
|
||||||
|
make_sales_invoice(sell_qty);
|
||||||
|
dialog.hide();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
make_sales_invoice(sell_qty);
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user