diff --git a/addons_extensions/consolidated_batch_payslip/static/src/components/pqgrid_batch_payslip/pqgrid_batch_payslip.js b/addons_extensions/consolidated_batch_payslip/static/src/components/pqgrid_batch_payslip/pqgrid_batch_payslip.js index e76225746..17882d048 100644 --- a/addons_extensions/consolidated_batch_payslip/static/src/components/pqgrid_batch_payslip/pqgrid_batch_payslip.js +++ b/addons_extensions/consolidated_batch_payslip/static/src/components/pqgrid_batch_payslip/pqgrid_batch_payslip.js @@ -1,10 +1,10 @@ /** @odoo-module **/ -import { standardWidgetProps } from "@web/views/widgets/standard_widget_props"; -import { Component, onMounted, useRef, useState, onWillStart } from "@odoo/owl"; -import { registry } from "@web/core/registry"; -import { useService } from "@web/core/utils/hooks"; -import { loadJS, loadCSS } from "@web/core/assets"; -import { rpc } from "@web/core/network/rpc"; +import {standardWidgetProps} from "@web/views/widgets/standard_widget_props"; +import {Component, onMounted, useRef, useState, onWillStart, onWillUpdateProps} from "@odoo/owl"; +import {registry} from "@web/core/registry"; +import {useService} from "@web/core/utils/hooks"; +import {loadJS, loadCSS} from "@web/core/assets"; +import {rpc} from "@web/core/network/rpc"; export class ConsolidatedPayslipGrid extends Component { static props = { @@ -34,6 +34,12 @@ export class ConsolidatedPayslipGrid extends Component { console.error("Grid element not found"); } }); + + onWillUpdateProps(async (nextProps) => { + if (nextProps.record.data.state !== this.props.record.data.state) { + await this.loadGrid(); + } + }); } async loadDependencies() { @@ -117,117 +123,106 @@ export class ConsolidatedPayslipGrid extends Component { } async renderGrid() { - if (!this.gridRef.el) return; - const columns = await this.getColumns(); - const agg = pq.aggregate; + if (!this.gridRef.el) return; + const columns = await this.getColumns(); + const agg = pq.aggregate; - // Define custom aggregate functions - agg.sum_ = function(arr, col) { - return " " + agg.sum(arr, col).toFixed(2).toString(); - }; - - const groupModel = { - on: true, - //dataIndx: ["employee_code",""], - collapsed: [false, true], - merge: true, - showSummary: [true, true], - grandSummary: true, - render: () => "" // hides the group title row text - }; - - - const gridOptions = { - - selectionModel: { type: 'row' }, - width: "100%", - height: "100%", - groupModel: groupModel, - editable: true, - stripeRows:false, - editModel: { saveKey: $.ui.keyCode.ENTER }, - filterModel: {on: true, mode: "AND", header: true, autoSearch: true, type: 'local', minLength: 1}, - dataModel: {data: this.state.rows, location: "local", sorting: "local", paging: "local"}, - cellSave: function (evt, ui) { - const payload = { - id: ui.rowData.id, - field: ui.dataIndx, - value: ui.newVal + // Define custom aggregate functions + agg.sum_ = function (arr, col) { + return " " + agg.sum(arr, col).toFixed(2).toString(); }; - updateData(payload); - }, - menuIcon: true, - menuUI:{tabs: ['hideCols']}, - colModel: columns, - postRenderInterval: -1, - toolbar: { - items: [ - { - type: 'button', - label: 'Refresh', - icon: 'ui-icon-refresh', - listener: () => this.loadGrid() - }, - { - type: 'button', - label: 'Save Changes', - icon: 'ui-icon-disk', - listener: () => this.saveChanges() - }, - { - type: 'button', - label: 'Recalculate LOP', - icon: 'ui-icon-calculator', - listener: () => this.recalculateLOP() - }, - { - type: 'select', - label: 'Format: ', - attr: 'id="export_format"', - options: [{ xlsx: 'Excel', csv: 'Csv', htm: 'Html', json: 'Json'}] - }, - { - type: 'button', - label: "Export", - icon: 'ui-icon-arrowthickstop-1-s', - listener: function () { - var format = $("#export_format").val(), - blob = this.exportData({ - //url: "/pro/demos/exportData", - format: format, - render: true - }); - if(typeof blob === "string"){ - blob = new Blob([blob]); + const groupModel = { + on: true, + //dataIndx: ["employee_code",""], + collapsed: [false, true], + merge: true, + showSummary: [true, true], + grandSummary: true, + render: () => "" // hides the group title row text + }; + + + const gridOptions = { + + selectionModel: {type: 'row'}, + width: "100%", + height: "100%", + groupModel: groupModel, + editable: true, + stripeRows: false, + editModel: {saveKey: $.ui.keyCode.ENTER}, + filterModel: {on: true, mode: "AND", header: true, autoSearch: true, type: 'local', minLength: 1}, + dataModel: {data: this.state.rows, location: "local", sorting: "local", paging: "local"}, + cellSave: function (evt, ui) { + const payload = { + id: ui.rowData.id, + field: ui.dataIndx, + value: ui.newVal + }; + updateData(payload); + }, + menuIcon: true, + menuUI: {tabs: ['hideCols']}, + colModel: columns, + postRenderInterval: -1, + toolbar: { + items: [ + { + type: 'button', + label: 'Refresh', + icon: 'ui-icon-refresh', + listener: () => this.loadGrid() + }, + { + type: 'select', + label: 'Format: ', + attr: 'id="export_format"', + options: [{xlsx: 'Excel', csv: 'Csv', htm: 'Html', json: 'Json'}] + }, + { + type: 'button', + label: "Export", + icon: 'ui-icon-arrowthickstop-1-s', + listener: function () { + + var format = $("#export_format").val(), + blob = this.exportData({ + //url: "/pro/demos/exportData", + format: format, + render: true + }); + if (typeof blob === "string") { + blob = new Blob([blob]); + } + saveAs(blob, "PaySheet." + format); } - saveAs(blob, "PaySheet."+ format ); - } + }, + ] + }, + }; + + function updateData(data) { + $.ajax({ + url: "/slip/update", + type: "POST", + contentType: "application/json", + data: JSON.stringify(data), + success: function (response) { + console.log("Update successful:", response); }, - ] - }, - }; - function updateData(data){ - $.ajax({ - url: "/slip/update", - type: "POST", - contentType: "application/json", - data: JSON.stringify(data), - success: function (response) { - console.log("Update successful:", response); - }, - error: function (xhr) { - console.error("Update failed:", xhr.responseText); - } - }); - }; + error: function (xhr) { + console.error("Update failed:", xhr.responseText); + } + }); + }; - // Apply CSS and initialize grid - $(this.gridRef.el) - .css({ height: '600px', width: '100%' }) - .pqGrid(gridOptions) - .pqGrid("refreshDataAndView"); + // Apply CSS and initialize grid + $(this.gridRef.el) + .css({height: '600px', width: '100%'}) + .pqGrid(gridOptions) + .pqGrid("refreshDataAndView"); } async refreshDataAndView() { @@ -293,14 +288,14 @@ export class ConsolidatedPayslipGrid extends Component { } async getColumns() { - const subCols = await this.getSubgridColumns(); + const subCols = await this.getSubgridColumns(); - return [ + const columns = [ { title: "Employee", dataIndx: "employee", width: 200, - filter: { type: 'textbox', condition: 'contain', listeners: ['keyup'] }, + filter: {type: 'textbox', condition: 'contain', listeners: ['keyup']}, editable: false, menuIcon: true, menuInHide: true @@ -309,7 +304,7 @@ export class ConsolidatedPayslipGrid extends Component { title: "Employee ID", dataIndx: "employee_code", width: 200, - filter: { type: 'textbox', condition: 'contain', listeners: ['keyup'] }, + filter: {type: 'textbox', condition: 'contain', listeners: ['keyup']}, editable: false, menuInHide: true }, @@ -317,7 +312,7 @@ export class ConsolidatedPayslipGrid extends Component { title: "Department", dataIndx: "department", width: 150, - filter: { type: 'textbox', condition: 'contain', listeners: ['keyup'] }, + filter: {type: 'textbox', condition: 'contain', listeners: ['keyup']}, editable: false }, { @@ -372,7 +367,7 @@ export class ConsolidatedPayslipGrid extends Component { width: 80, dataType: "integer", editable: (rowData) => rowData.state === 'draft', - summary: { type: "sum_" } + summary: {type: "sum_"} }, { title: "Sick Leave Balance", @@ -380,7 +375,7 @@ export class ConsolidatedPayslipGrid extends Component { width: 100, dataType: "float", editable: false, - summary: { type: "sum_" }, + summary: {type: "sum_"}, format: "##,##0.00" }, { @@ -389,7 +384,7 @@ export class ConsolidatedPayslipGrid extends Component { width: 100, dataType: "float", editable: false, - summary: { type: "sum_" }, + summary: {type: "sum_"}, format: "##,##0.00" }, { @@ -398,7 +393,7 @@ export class ConsolidatedPayslipGrid extends Component { width: 100, dataType: "float", editable: false, - summary: { type: "sum_" }, + summary: {type: "sum_"}, format: "##,##0.00" }, // { @@ -438,67 +433,77 @@ export class ConsolidatedPayslipGrid extends Component { return `${state}`; } }, - ...subCols, - { - title: "View", - width: 120, - editable: false, - summary:false, - render: function (ui) { - return "" - }, - postRender: function (ui) { - var grid = this, - $cell = grid.getCell(ui); - $cell.find(".row-btn-view") - .button({ icons: { primary: 'ui-icon-extlink'} }) - .on("click", async function (evt) { - const res = await odoo.__WOWL_DEBUG__.root.orm.call('hr.payslip','action_open_payslips',[ui.rowData.id]) + ...subCols, + { + title: "View", + width: 120, + editable: false, + summary: false, + render: function (ui) { + return "" + }, + postRender: function (ui) { + var grid = this, + $cell = grid.getCell(ui); + $cell.find(".row-btn-view") + .button({icons: {primary: 'ui-icon-extlink'}}) + .on("click", async function (evt) { + const res = await odoo.__WOWL_DEBUG__.root.orm.call('hr.payslip', 'action_open_payslips', [ui.rowData.id]) // res.views = [[false, "form"]], await odoo.__WOWL_DEBUG__.root.actionService.doAction(res) }); - } + } - }, - { - title: "Edit", - width: 120, - editable: false, - render: function (ui) { - return "" - }, - postRender: function (ui) { + }, + + ]; + if (this.props.record.data.state !== "paid") { + columns.push( + { + title: "Edit", + width: 120, + editable: false, + render: function (ui) { + if (ui.rowData.state == 'paid') { + return "" + } + return "" + }, + postRender: function (ui) { var grid = this, $cell = grid.getCell(ui); $cell.find(".row-btn-edit") - .button({ icons: { primary: 'ui-icon-pencil'} }) + .button({icons: {primary: 'ui-icon-pencil'}}) .on("click", async function (evt) { - const res = await odoo.__WOWL_DEBUG__.root.orm.call('hr.payslip','action_edit_payslip_lines',[ui.rowData.id]) - res.views = [[false, "form"]], - await odoo.__WOWL_DEBUG__.root.actionService.doAction(res) - }); + const res = await odoo.__WOWL_DEBUG__.root.orm.call('hr.payslip', 'action_edit_payslip_lines', [ui.rowData.id]) + res.views = [[false, "form"]], + await odoo.__WOWL_DEBUG__.root.actionService.doAction(res) + }); } - } - ]; + } + ) + } + + return columns } async getSubgridColumns() { const response = await this.orm.call( - "hr.payslip.run", - "sub_columns", - [this.state.payslipRunId] - ); - return response || []; + "hr.payslip.run", + "sub_columns", + [this.state.payslipRunId] + ); + return response || []; } async refreshGrid() { try { await this.loadGridData(); $(this.gridRef.el).pqGrid("refreshDataAndView"); - this.notification.add("Data refreshed successfully", { type: 'success' }); + this.notification.add("Data refreshed successfully", {type: 'success'}); } catch (error) { console.error("Error refreshing grid:", error); - this.notification.add("Error refreshing data", { type: 'danger' }); + this.notification.add("Error refreshing data", {type: 'danger'}); } } @@ -513,10 +518,10 @@ export class ConsolidatedPayslipGrid extends Component { [this.state.payslipRunId, updatedData] ); await this.refreshGrid(); - this.notification.add("Changes saved successfully", { type: 'success' }); + this.notification.add("Changes saved successfully", {type: 'success'}); } catch (error) { console.error("Error saving data:", error); - this.notification.add("Error saving changes", { type: 'danger' }); + this.notification.add("Error saving changes", {type: 'danger'}); } } @@ -528,10 +533,10 @@ export class ConsolidatedPayslipGrid extends Component { [this.state.payslipRunId] ); await this.refreshGrid(); - this.notification.add("LOP days recalculated successfully", { type: 'success' }); + this.notification.add("LOP days recalculated successfully", {type: 'success'}); } catch (error) { console.error("Error recalculating LOP:", error); - this.notification.add("Error recalculating LOP", { type: 'danger' }); + this.notification.add("Error recalculating LOP", {type: 'danger'}); } } @@ -543,10 +548,10 @@ export class ConsolidatedPayslipGrid extends Component { [this.state.payslipRunId] ); await this.refreshGrid(); - this.notification.add("All records validated successfully", { type: 'success' }); + this.notification.add("All records validated successfully", {type: 'success'}); } catch (error) { console.error("Error validating records:", error); - this.notification.add("Error validating records", { type: 'danger' }); + this.notification.add("Error validating records", {type: 'danger'}); } } } diff --git a/addons_extensions/hr_payroll/views/ftp_payslip.xml b/addons_extensions/hr_payroll/views/ftp_payslip.xml index ee8580c40..6723c9e3b 100644 --- a/addons_extensions/hr_payroll/views/ftp_payslip.xml +++ b/addons_extensions/hr_payroll/views/ftp_payslip.xml @@ -122,7 +122,6 @@