Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (c) 2023, New Indictranstech and contributors
- // For license information, please see license.txt
- frappe.ui.form.on('Pradan Budget', {
- refresh: function(frm) {
- frm.disable_save();
- frm.disable_form();
- add_buttons(frm);
- }
- });
- frappe.ui.form.on('Pradan Budget Items', {
- allocate: function(frm, cdt, cdn){
- let child = locals[cdt][cdn];
- if(child.allocated == 0 && frm.doc.docstatus == 1){
- budget_allocation_popup(frm, cdt, cdn);
- }
- else {
- frm.fields_dict.allocations.grid.update_docfield_property('allocate', "hidden", 1);
- frappe.throw('Budget allocation will be possible only after defining availability.')
- }
- }
- });
- function budget_allocation_popup(frm, cdt, cdn){
- var child = locals[cdt][cdn];
- let d = new frappe.ui.Dialog({
- title: 'Team Allocation',
- size: "large",
- fields: [
- {
- label: "Available Amount",
- fieldname: "allocated_amount",
- fieldtype: "Currency",
- read_only: 1,
- default: child.available_amount
- },
- {
- label: "Team wise Budget",
- fieldname: "team_wise_budget",
- fieldtype: "Table",
- reqd: 1,
- cannot_add_rows: true,
- in_place_edit: true,
- fields: [
- {
- fieldtype: 'Link',
- label: 'Project',
- fieldname: 'project',
- options: 'Project',
- in_list_view: 1,
- reqd: 1,
- read_only: 1
- },
- {
- fieldtype: 'Link',
- label: 'Teams',
- fieldname: 'teams',
- options: 'Branch',
- in_list_view: 1,
- reqd: 1,
- read_only: 1
- },
- {
- fieldtype: 'Currency',
- label: 'Allocated Amount',
- fieldname: 'allocated_amount',
- in_list_view: 1,
- reqd: 1,
- default: 0
- }
- ]
- }
- ],
- primary_action_label: 'Allocate',
- primary_action(values) {
- allocate_budget_to_teams(frm, child, values);
- d.hide();
- }
- });
- frappe.call({
- method: 'pradan.pradan.doctype.pradan_budget.pradan_budget.get_team_wise_budget',
- args: {
- project: child.project,
- available_amount: child.available_amount
- },
- freeze: true,
- freeze_message: 'Fetching teams..',
- callback: (r) => {
- if(r.message){
- let data = r.message;
- d.fields_dict.team_wise_budget.df.data = data
- d.fields_dict.team_wise_budget.grid.refresh();
- }
- else {
- frappe.throw('No team has allocated to this Project')
- }
- },
- });
- d.show();
- }
- function allocate_budget_to_teams(frm, child, values){
- frappe.call({
- method: 'pradan.pradan.doctype.pradan_budget.pradan_budget.allocate_budget_to_teams',
- args: {
- project: child.project,
- sub_budget_item: child.sub_budget_item,
- fiscal_year: child.fiscal_year,
- values: values
- },
- freeze: true,
- freeze_message: 'Allocating to teams..',
- callback: (r) => {
- frm.reload_doc();
- },
- })
- }
- function add_buttons(frm){
- if(!frm.is_new()){
- if(frm.doc.workflow_state != 'Rejected'){
- frm.add_custom_button('Detailed View', () => {
- frappe.set_route('Form', 'Budget Tool', 'Budget Tool');
- }).addClass('btn-primary');
- }
- if(['Pending', 'Approved'].includes(frm.doc.workflow_state)){
- frm.add_custom_button('Reject with Feedback', () => {
- let d = new frappe.ui.Dialog({
- title: 'Rejection Feedback',
- fields: [
- {
- label: 'Feedback',
- fieldname: 'feedback',
- fieldtype: 'Small Text',
- reqd: 1
- }
- ],
- primary_action_label: 'Reject',
- primary_action(values) {
- frappe.call({
- method: 'pradan.pradan.doctype.pradan_budget.pradan_budget.reject_with_feedback',
- args: {
- budget_id: frm.doc.name,
- feedback: values.feedback
- },
- freeze: true,
- freeze_message: 'Rejecting with feedback',
- callback: (r) => {
- frm.reload_doc();
- },
- });
- d.hide();
- }
- });
- d.show();
- }).addClass('btn-danger');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement