chore: Use JSON style response and use ORM
- Use JSON style response for report columns - Use ORM instead of frappe.db.sql - Remove returned % from list view
This commit is contained in:
parent
307bd01504
commit
724e16bca1
@ -14,19 +14,93 @@ def execute(filters=None):
|
|||||||
|
|
||||||
def get_column():
|
def get_column():
|
||||||
return [
|
return [
|
||||||
_("Delivery Note") + ":Link/Delivery Note:160",
|
{
|
||||||
_("Date") + ":Date:100",
|
"label": _("Delivery Note"),
|
||||||
_("Customer") + ":Link/Customer:120",
|
"fieldname": "name",
|
||||||
_("Customer Name") + "::120",
|
"fieldtype": "Link",
|
||||||
_("Item Code") + ":Link/Item:120",
|
"options": "Delivery Note",
|
||||||
_("Amount") + ":Currency:100",
|
"width": 160
|
||||||
_("Billed Amount") + ":Currency:100",
|
},
|
||||||
_("Returned Amount") + ":Currency:120",
|
{
|
||||||
_("Pending Amount") + ":Currency:100",
|
"label": _("Date"),
|
||||||
_("Item Name") + "::120",
|
"fieldname": "date",
|
||||||
_("Description") + "::120",
|
"fieldtype": "Date",
|
||||||
_("Project") + ":Link/Project:120",
|
"width": 100
|
||||||
_("Company") + ":Link/Company:120",
|
},
|
||||||
|
{
|
||||||
|
"label": _("Customer"),
|
||||||
|
"fieldname": "customer",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Customer",
|
||||||
|
"width": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Customer Name"),
|
||||||
|
"fieldname": "customer_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"width": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Item Code"),
|
||||||
|
"fieldname": "item_code",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Item",
|
||||||
|
"width": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Amount"),
|
||||||
|
"fieldname": "amount",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"width": 100,
|
||||||
|
"options": "Company:company:default_currency"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Billed Amount"),
|
||||||
|
"fieldname": "billed_amount",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"width": 100,
|
||||||
|
"options": "Company:company:default_currency"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Returned Amount"),
|
||||||
|
"fieldname": "returned_amount",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"width": 120,
|
||||||
|
"options": "Company:company:default_currency"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Pending Amount"),
|
||||||
|
"fieldname": "pending_amount",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"width": 120,
|
||||||
|
"options": "Company:company:default_currency"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Item Name"),
|
||||||
|
"fieldname": "item_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"width": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Description"),
|
||||||
|
"fieldname": "description",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"width": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Project"),
|
||||||
|
"fieldname": "project",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Project",
|
||||||
|
"width": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Company"),
|
||||||
|
"fieldname": "company",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Company",
|
||||||
|
"width": 120
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_args():
|
def get_args():
|
||||||
|
@ -14,19 +14,93 @@ def execute(filters=None):
|
|||||||
|
|
||||||
def get_column():
|
def get_column():
|
||||||
return [
|
return [
|
||||||
_("Purchase Receipt") + ":Link/Purchase Receipt:160",
|
{
|
||||||
_("Date") + ":Date:100",
|
"label": _("Purchase Receipt"),
|
||||||
_("Supplier") + ":Link/Supplier:120",
|
"fieldname": "name",
|
||||||
_("Supplier Name") + "::120",
|
"fieldtype": "Link",
|
||||||
_("Item Code") + ":Link/Item:120",
|
"options": "Purchase Receipt",
|
||||||
_("Amount") + ":Currency:100",
|
"width": 160
|
||||||
_("Billed Amount") + ":Currency:100",
|
},
|
||||||
_("Returned Amount") + ":Currency:120",
|
{
|
||||||
_("Pending Amount") + ":Currency:120",
|
"label": _("Date"),
|
||||||
_("Item Name") + "::120",
|
"fieldname": "date",
|
||||||
_("Description") + "::120",
|
"fieldtype": "Date",
|
||||||
_("Project") + ":Link/Project:120",
|
"width": 100
|
||||||
_("Company") + ":Link/Company:120",
|
},
|
||||||
|
{
|
||||||
|
"label": _("Supplier"),
|
||||||
|
"fieldname": "supplier",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Supplier",
|
||||||
|
"width": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Supplier Name"),
|
||||||
|
"fieldname": "supplier_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"width": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Item Code"),
|
||||||
|
"fieldname": "item_code",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Item",
|
||||||
|
"width": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Amount"),
|
||||||
|
"fieldname": "amount",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"width": 100,
|
||||||
|
"options": "Company:company:default_currency"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Billed Amount"),
|
||||||
|
"fieldname": "billed_amount",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"width": 100,
|
||||||
|
"options": "Company:company:default_currency"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Returned Amount"),
|
||||||
|
"fieldname": "returned_amount",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"width": 120,
|
||||||
|
"options": "Company:company:default_currency"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Pending Amount"),
|
||||||
|
"fieldname": "pending_amount",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"width": 120,
|
||||||
|
"options": "Company:company:default_currency"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Item Name"),
|
||||||
|
"fieldname": "item_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"width": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Description"),
|
||||||
|
"fieldname": "description",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"width": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Project"),
|
||||||
|
"fieldname": "project",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Project",
|
||||||
|
"width": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Company"),
|
||||||
|
"fieldname": "company",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Company",
|
||||||
|
"width": 120
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_args():
|
def get_args():
|
||||||
|
@ -206,35 +206,26 @@ def get_already_returned_items(doc):
|
|||||||
def get_returned_qty_map_for_row(row_name, doctype):
|
def get_returned_qty_map_for_row(row_name, doctype):
|
||||||
child_doctype = doctype + " Item"
|
child_doctype = doctype + " Item"
|
||||||
reference_field = frappe.scrub(child_doctype) if doctype == "Purchase Receipt" else "dn_detail"
|
reference_field = frappe.scrub(child_doctype) if doctype == "Purchase Receipt" else "dn_detail"
|
||||||
reference_field = "child." + reference_field
|
|
||||||
columns = ""
|
fields = [
|
||||||
|
"sum(abs(`tab{0}`.qty)) as qty".format(child_doctype),
|
||||||
|
"sum(abs(`tab{0}`.stock_qty)) as stock_qty".format(child_doctype)
|
||||||
|
]
|
||||||
|
|
||||||
if doctype == "Purchase Receipt":
|
if doctype == "Purchase Receipt":
|
||||||
columns += ", sum(abs(child.rejected_qty)) as rejected_qty, \
|
fields += [
|
||||||
sum(abs(child.received_qty)) as received_qty, \
|
"sum(abs(`tab{0}`.rejected_qty)) as rejected_qty".format(child_doctype),
|
||||||
sum(abs(child.received_stock_qty)) as received_stock_qty"
|
"sum(abs(`tab{0}`.received_qty)) as received_qty".format(child_doctype),
|
||||||
|
"sum(abs(`tab{0}`.received_stock_qty)) as received_stock_qty".format(child_doctype)
|
||||||
|
]
|
||||||
|
|
||||||
data = frappe.db.sql("""
|
data = frappe.db.get_list(doctype,
|
||||||
select
|
fields = fields,
|
||||||
sum(abs(child.qty)) as qty,
|
filters = [
|
||||||
sum(abs(child.stock_qty)) as stock_qty,
|
[doctype, "docstatus", "=", 1],
|
||||||
%(columns)s
|
[doctype, "is_return", "=", 1],
|
||||||
from
|
[child_doctype, reference_field, "=", row_name]
|
||||||
`tab{0}` child, `tab{1}` parent
|
])
|
||||||
where
|
|
||||||
child.parent = parent.name
|
|
||||||
and parent.docstatus = 1
|
|
||||||
and parent.is_return = 1
|
|
||||||
and {2} = %(row_name)s
|
|
||||||
""".format(child_doctype, doctype, reference_field),
|
|
||||||
{
|
|
||||||
"row_name": row_name,
|
|
||||||
"columns": columns,
|
|
||||||
"child_doctype": child_doctype,
|
|
||||||
"doctype": doctype,
|
|
||||||
"reference_field": reference_field
|
|
||||||
},
|
|
||||||
as_dict=1)
|
|
||||||
|
|
||||||
return data[0]
|
return data[0]
|
||||||
|
|
||||||
|
@ -1257,7 +1257,6 @@
|
|||||||
"depends_on": "eval:!doc.__islocal",
|
"depends_on": "eval:!doc.__islocal",
|
||||||
"fieldname": "per_returned",
|
"fieldname": "per_returned",
|
||||||
"fieldtype": "Percent",
|
"fieldtype": "Percent",
|
||||||
"in_list_view": 1,
|
|
||||||
"label": "% Returned",
|
"label": "% Returned",
|
||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
@ -1268,7 +1267,7 @@
|
|||||||
"idx": 146,
|
"idx": 146,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-11-19 11:22:09.056684",
|
"modified": "2020-11-30 12:54:45.407289",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Delivery Note",
|
"name": "Delivery Note",
|
||||||
|
@ -1110,7 +1110,6 @@
|
|||||||
"depends_on": "eval:!doc.__islocal",
|
"depends_on": "eval:!doc.__islocal",
|
||||||
"fieldname": "per_returned",
|
"fieldname": "per_returned",
|
||||||
"fieldtype": "Percent",
|
"fieldtype": "Percent",
|
||||||
"in_list_view": 1,
|
|
||||||
"label": "% Returned",
|
"label": "% Returned",
|
||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
@ -1121,7 +1120,7 @@
|
|||||||
"idx": 261,
|
"idx": 261,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-11-19 11:21:25.465966",
|
"modified": "2020-11-30 12:54:23.278500",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Purchase Receipt",
|
"name": "Purchase Receipt",
|
||||||
|
@ -550,19 +550,17 @@ def update_billing_percentage(pr_doc, update_modified=True):
|
|||||||
# Update Billing % based on pending accepted qty
|
# Update Billing % based on pending accepted qty
|
||||||
total_amount, total_billed_amount = 0, 0
|
total_amount, total_billed_amount = 0, 0
|
||||||
for item in pr_doc.items:
|
for item in pr_doc.items:
|
||||||
returned_qty = frappe.db.sql("""
|
return_data = frappe.db.get_list("Purchase Receipt",
|
||||||
select sum(abs(child.qty)) as qty
|
fields = [
|
||||||
from
|
"sum(abs(`tabPurchase Receipt Item`.qty)) as qty"
|
||||||
`tabPurchase Receipt Item` child,
|
],
|
||||||
`tabPurchase Receipt` parent
|
filters = [
|
||||||
where
|
["Purchase Receipt", "docstatus", "=", 1],
|
||||||
child.parent = parent.name
|
["Purchase Receipt", "is_return", "=", 1],
|
||||||
and parent.docstatus = 1
|
["Purchase Receipt Item", "purchase_receipt_item", "=", item.name]
|
||||||
and parent.is_return = 1
|
])
|
||||||
and child.purchase_receipt_item = %(row_name)s
|
|
||||||
""", {"row_name": item.name})
|
|
||||||
returned_qty = returned_qty[0][0] if returned_qty else 0
|
|
||||||
|
|
||||||
|
returned_qty = return_data[0].qty if return_data else 0
|
||||||
returned_amount = flt(returned_qty) * flt(item.rate)
|
returned_amount = flt(returned_qty) * flt(item.rate)
|
||||||
pending_amount = flt(item.amount) - returned_amount
|
pending_amount = flt(item.amount) - returned_amount
|
||||||
total_billable_amount = pending_amount if item.billed_amt <= pending_amount else item.billed_amt
|
total_billable_amount = pending_amount if item.billed_amt <= pending_amount else item.billed_amt
|
||||||
|
Loading…
x
Reference in New Issue
Block a user