Skip to content

Commit

Permalink
Merge pull request #10 from navariltd/staging
Browse files Browse the repository at this point in the history
fix: drop_meter_reading api
  • Loading branch information
muruthigitau authored Oct 17, 2024
2 parents 2d58914 + 3d99290 commit 0d787f8
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 50 deletions.
27 changes: 27 additions & 0 deletions utility_billing/utility_billing/apis/delete_doc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import frappe

@frappe.whitelist(allow_guest=True)
def drop_meter_reading():
try:
meter_readings = frappe.get_all("Meter Reading", pluck="name")
for reading in meter_readings:
frappe.delete_doc("Meter Reading", reading)

meter_reading_items = frappe.get_all("Meter Reading Item", pluck="name")
for item in meter_reading_items:
frappe.delete_doc("Meter Reading Item", item)

meter_reading_rates = frappe.get_all("Meter Reading Rate", pluck="name")
for rate in meter_reading_rates:
frappe.delete_doc("Meter Reading Rate", rate)

frappe.db.commit()

return {
"status": "success",
"message": "All entries in Meter Reading, Meter Reading Item, and Meter Reading Rate have been successfully deleted."
}

except Exception as e:
frappe.log_error(f"An error occurred while deleting records: {str(e)}", "Drop Reading Error")
return {"status": "error", "message": str(e)}
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,14 @@
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-10-17 07:30:33.471183",
"modified": "2024-10-17 08:27:35.854008",
"modified_by": "Administrator",
"module": "Utility Billing",
"name": "Meter Reading Rate",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"permissions": [],
"sort_field": "creation",
"sort_order": "DESC",
"states": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,65 +85,63 @@ frappe.ui.form.on("Utility Service Request Item", {
let row = locals[cdt][cdn];
if (row.item_code) {
frappe.call({
method: "frappe.client.get",
args: { doctype: "Item", name: row.item_code },
method: "utility_billing.utility_billing.doctype.utility_service_request.utility_service_request.get_item_details",
args: {
item_code: row.item_code,
price_list: frm.doc.price_list,
},
callback: function (r) {
if (r.message) {
let item = r.message;
frappe.model.set_value(cdt, cdn, {
item_name: item.item_name,
uom: item.stock_uom,
rate: item.standard_rate,
warehouse: item.default_warehouse,
uom: item.uom,
rate: item.rate,
warehouse: item.warehouse,
description: item.description,
qty: 1,
conversion_factor: (item.uoms[0] || {}).conversion_factor || 1,
brand: item.brand || null,
conversion_factor: item.conversion_factor,
brand: item.brand,
item_group: item.item_group,
stock_uom: item.stock_uom,
bom_no: item.default_bom,
bom_no: item.bom_no,
weight_per_unit: item.weight_per_unit,
weight_uom: item.weight_uom || null,
weight_uom: item.weight_uom,
});

// Fetch price list rate if available
if (frm.doc.price_list) {
frappe.call({
method: "frappe.client.get_list",
args: {
doctype: "Item Price",
filters: {
price_list: frm.doc.price_list,
item_code: row.item_code,
},
fields: ["price_list_rate"],
},
callback: function (res) {
let rate =
res.message[0]?.price_list_rate || item.standard_rate;
let amount = rate * row.qty;
frappe.model.set_value(cdt, cdn, {
rate: rate,
price_list_rate: rate,
amount: amount,
base_price_list_rate: rate,
});
},
});
}
let amount = flt(item.rate) * flt(row.qty || 1);
frappe.model.set_value(cdt, cdn, {
rate: item.rate,
amount: amount,
base_price_list_rate: item.rate,
});
}
},
});
}
},

rate: function (frm, cdt, cdn) {
calculate_amount(frm, cdt, cdn);
},

qty: function (frm, cdt, cdn) {
calculate_amount(frm, cdt, cdn);
},

delivery_date: function (frm) {
if (!frm.doc.delivery_date) {
erpnext.utils.copy_value_in_all_rows(frm.doc, null, null, "items", "delivery_date");
}
},
});

function calculate_amount(frm, cdt, cdn) {
let row = locals[cdt][cdn];
let amount = flt(row.rate) * flt(row.qty);
frappe.model.set_value(cdt, cdn, "amount", amount);
}

function fetch_customer_details(frm) {
frappe.call({
method: "utility_billing.utility_billing.doctype.meter_reading.meter_reading.get_customer_details",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import frappe
from frappe.contacts.address_and_contact import load_address_and_contact
from frappe.model.document import Document

from frappe import _

class UtilityServiceRequest(Document):
def onload(self):
Expand Down Expand Up @@ -147,3 +147,40 @@ def check_request_status(request_name):
status = ""

return status


@frappe.whitelist()
def get_item_details(item_code, price_list=None):
item = frappe.get_doc("Item", item_code)

if not item:
frappe.throw(_("Item not found"))

default_warehouse = getattr(item, 'default_warehouse', None)

item_details = {
"item_name": item.item_name,
"uom": item.stock_uom,
"rate": item.standard_rate,
"warehouse": default_warehouse,
"description": item.description,
"qty": 1,
"conversion_factor": (item.uoms[0] or {}).get('conversion_factor', 1) if item.uoms else 1,
"brand": item.brand,
"item_group": item.item_group,
"stock_uom": item.stock_uom,
"bom_no": item.default_bom,
"weight_per_unit": item.weight_per_unit,
"weight_uom": item.weight_uom
}

if price_list:
item_price = frappe.db.get_value(
"Item Price",
filters={"price_list": price_list, "item_code": item_code},
fieldname=["price_list_rate"]
)
if item_price:
item_details["rate"] = item_price

return item_details

0 comments on commit 0d787f8

Please sign in to comment.