Skip to content

Commit

Permalink
Merge pull request #24 from umarless/pragati_nirjay
Browse files Browse the repository at this point in the history
|nirjay_customization|added new doctype multi purchase order and chil…
  • Loading branch information
pragatihybrow authored Dec 23, 2024
2 parents 093769f + ddf0f54 commit c5d82c1
Show file tree
Hide file tree
Showing 11 changed files with 710 additions and 60 deletions.
376 changes: 316 additions & 60 deletions nirjay_customization/nirjay_customization/custom/purchase_invoice.json

Large diffs are not rendered by default.

Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Copyright (c) 2024, Hybrowlabs Technologies and contributors
// For license information, please see license.txt

frappe.ui.form.on('Multi Purchase Order', {
// Trigger when the form is loaded or refreshed
refresh: function (frm) {
// Recalculate grand total on refresh
calculate_grand_total(frm);


if (frm.doc.docstatus === 1) {
frm.add_custom_button(__('Purchase Invoice'), function () {
frappe.model.open_mapped_doc({
method: "nirjay_customization.override.purchase_invoice.make_purchase_invoice",
frm: frm,
});
}, __("Create"));
}

},

// Custom function for adding purchase orders
add_po: function (frm) {
let selectedOrders = frm.doc.purchase_order
? frm.doc.purchase_order.split(',').map(order => order.trim()).filter(Boolean)
: [];

frappe.call({
method: 'frappe.client.get_list',
args: {
doctype: 'Purchase Order',
fields: ['name', 'grand_total'], // Fetch name and grand total of Purchase Orders
filters: {
docstatus: ['!=', 2] // Exclude canceled Purchase Orders
},
limit_page_length: 0,
},
callback: function (response) {
if (response.message) {
let options = response.message
.filter(po => !selectedOrders.includes(po.name)) // Exclude selected orders
.map(po => ({
value: po.name,
description: `Grand Total: ${po.grand_total}`
})); // Add grand total to description

const dialog = new frappe.ui.Dialog({
title: __('Select Purchase Order'),
fields: [
{
label: __("Select Purchase Order"),
fieldtype: "MultiSelectList",
fieldname: "purchase_order",
placeholder: "Select Purchase Orders",
options: options,
reqd: 1,
get_data: function () {
return options;
}
}
],
primary_action_label: __('Submit'),
primary_action: function (values) {
let newOrders = values['purchase_order'] || [];
let duplicates = newOrders.filter(order => selectedOrders.includes(order));

if (duplicates.length > 0) {
frappe.msgprint(
__("The following Purchase Orders are already selected: {0}.", [duplicates.join(', ')])
);
} else {
selectedOrders = [...new Set([...selectedOrders, ...newOrders])];
frm.set_value("purchase_order", selectedOrders.join(', '));
frm.refresh_field('purchase_order');

// Add selected Purchase Orders to the child table
response.message.forEach(po => {
if (newOrders.includes(po.name) && !frm.doc.items.some(row => row.purchase_order === po.name)) {
let newRow = frm.add_child('items');
newRow.purchase_order = po.name;
newRow.purchase_order_grand_total = po.grand_total; // Set grand total
}
});

frm.refresh_field('items'); // Refresh the 'items' child table
calculate_grand_total(frm); // Update the parent grand total
}

dialog.hide();
$('body').removeClass('modal-open');
}
});

dialog.show();
$('body').addClass('modal-open');

let userCount = options.length;
let dynamicHeight = userCount * 100;
if (userCount > 10) {
dynamicHeight = 300;
}

dialog.$wrapper.find('.modal-body').css({
"overflow-y": "auto",
"height": dynamicHeight + "px",
"max-height": "90vh"
});
} else {
frappe.msgprint(__('No Purchase Orders found.'));
}
}
});
}
});

function calculate_grand_total(frm) {
let total = 0;
(frm.doc.items || []).forEach(row => {
total += row.total || 0;
});

frm.set_value('purchase_order_grand_total', total);
frm.refresh_field('purchase_order_grand_total');
frm.save()
}

frappe.ui.form.on('Multi Purchase Order Item', {
items_add: function (frm) {
calculate_grand_total(frm);
},
items_remove: function (frm) {
calculate_grand_total(frm);
},
purchase_order_grand_total: function (frm) {
calculate_grand_total(frm);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "naming_series:",
"creation": "2024-12-23 10:23:40.429207",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"section_break_c73f",
"amended_from",
"naming_series",
"purchase_order",
"add_po",
"items",
"purchase_order_grand_total",
"section_break_mhqj",
"currency",
"exchange_rate",
"price_list"
],
"fields": [
{
"fieldname": "section_break_c73f",
"fieldtype": "Section Break"
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "Multi Purchase Order",
"print_hide": 1,
"read_only": 1,
"search_index": 1
},
{
"fieldname": "purchase_order",
"fieldtype": "Small Text",
"label": "Purchase Order"
},
{
"fieldname": "add_po",
"fieldtype": "Button",
"label": "Select Purchase Order"
},
{
"fieldname": "items",
"fieldtype": "Table",
"label": "Purchase Order",
"options": "Purchase Order Item CT"
},
{
"default": "PO.FY.-",
"fieldname": "naming_series",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Series",
"no_copy": 1,
"options": "PO.FY.-",
"reqd": 1
},
{
"fieldname": "purchase_order_grand_total",
"fieldtype": "Float",
"label": "Purchase Order Grand Total"
},
{
"fieldname": "section_break_mhqj",
"fieldtype": "Section Break",
"label": "Currency and Price List"
},
{
"fieldname": "currency",
"fieldtype": "Link",
"label": "Currency",
"options": "Currency"
},
{
"fieldname": "exchange_rate",
"fieldtype": "Float",
"label": "Exchange Rate"
},
{
"fieldname": "price_list",
"fieldtype": "Link",
"label": "Price List",
"options": "Price List"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-12-23 12:26:09.216182",
"modified_by": "Administrator",
"module": "Nirjay Customization",
"name": "Multi Purchase Order",
"naming_rule": "By \"Naming Series\" field",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"submit": 1,
"write": 1
}
],
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2024, Hybrowlabs Technologies and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class MultiPurchaseOrder(Document):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2024, Hybrowlabs Technologies and Contributors
# See license.txt

# import frappe
from frappe.tests import IntegrationTestCase, UnitTestCase


# On IntegrationTestCase, the doctype test records and all
# link-field test record depdendencies are recursively loaded
# Use these module variables to add/remove to/from that list
EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]


class UnitTestMultiPurchaseOrder(UnitTestCase):
"""
Unit tests for MultiPurchaseOrder.
Use this class for testing individual functions and methods.
"""

pass


class IntegrationTestMultiPurchaseOrder(IntegrationTestCase):
"""
Integration tests for MultiPurchaseOrder.
Use this class for testing interactions between multiple components.
"""

pass
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2024-12-23 10:35:42.792925",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"purchase_order",
"total",
"taxable_amount",
"status"
],
"fields": [
{
"fieldname": "purchase_order",
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Purchase Order",
"options": "Purchase Order"
},
{
"fetch_from": "purchase_order.base_total",
"fieldname": "total",
"fieldtype": "Float",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Grand Total"
},
{
"fieldname": "taxable_amount",
"fieldtype": "Float",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Taxable Amount\t"
},
{
"fetch_from": "purchase_order.status",
"fieldname": "status",
"fieldtype": "Select",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Status",
"options": "\nDraft\nOn Hold\nTo Receive and Bill\nTo Bill\nTo Receive\nCompleted\nCancelled\nClosed\nDelivered"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-12-23 11:22:15.586721",
"modified_by": "Administrator",
"module": "Nirjay Customization",
"name": "Purchase Order Item CT",
"owner": "Administrator",
"permissions": [],
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2024, Hybrowlabs Technologies and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class PurchaseOrderItemCT(Document):
pass
Loading

0 comments on commit c5d82c1

Please sign in to comment.