/** @odoo-module **/ import { registry } from '@web/core/registry'; import { ListController } from "@web/views/list/list_controller"; import { listView } from "@web/views/list/list_view"; import { useState, useRef } from "@odoo/owl"; import { useListener, useService} from "@web/core/utils/hooks"; export class AccountMoveLineListController extends ListController { constructor() { super(...arguments); this.resIdList = []; } setup(){ super.setup(); this.state = useState({ selectedRecordId: null , selectedRecordIds: [],}); this.action = useService("action") this.orm = useService("orm") } async openRecord(record) { const kanban_row = this.__owl__.bdom.parentEl.ownerDocument.querySelector(`tr[data-id]`); const data_id = parseInt(kanban_row.getAttribute('data-id')) var data = await this.orm.call('account.bank.statement.line', 'update_match_row_data', [record.resId]) await this.orm.call('account.bank.statement.line', 'write', [[data_id], { lines_widget_json: JSON.stringify(data) }]); const rowSelector = this.__owl__.bdom.parentEl.querySelector(`tr[data-id='${record.id}']`) if (!record.clickCount) { record.clickCount = true rowSelector.style.backgroundColor = "#d1ecf1"; } else { // Set the default background color here record.clickCount = false; rowSelector.style.backgroundColor = "white"; } const currencySymbol = await this.orm.call('res.currency', 'read',[record.data.currency_id[0]]) const mainKanbanDiv = this.__owl__.bdom.parentEl.ownerDocument.querySelector('#base_accounting_reconcile') const existingRow = this.__owl__.bdom.parentEl.ownerDocument.querySelector(`tr[data-resId="${record.resId}"]`) const stateLineRow = this.__owl__.bdom.parentEl.ownerDocument.querySelector('.statement_row') if (stateLineRow){ const dataIdValue = stateLineRow.getAttribute('data-id'); if(dataIdValue == record.resId){ mainKanbanDiv.removeChild(stateLineRow); } } if (existingRow) { mainKanbanDiv.removeChild(existingRow); } else { // If the row doesn't exist, create and add it const dateObject = new Date(record.data.date); const year = dateObject.getFullYear(); const month = String(dateObject.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed const day = String(dateObject.getDate()).padStart(2, '0'); const formattedDate = `${year}-${month}-${day}`; let amount = parseFloat(record.data.amount_residual); let debitColumn = ''; let creditColumn = ''; let partnerName = ''; let moveId = ''; // Check if partner_id exists and is not empty if (record.data.partner_id && record.data.partner_id[1]) { partnerName = record.data.partner_id[1]; } if (record.data.move_id && record.data.move_id[1]) { moveId = `
${record.data.move_id[1]}`; } if (amount < 0) { debitColumn = `${currencySymbol[0].symbol} ${-amount}`; } else { creditColumn = `${currencySymbol[0].symbol} ${amount}`; } const newRow = document.createElement('tr'); newRow.setAttribute('data-resId', record.resId); // Set a unique identifier for the row if (debitColumn !== '') { newRow.innerHTML = `${record.data.account_id[1]} ${moveId} : ${record.data.name} ${partnerName} ${formattedDate} ${debitColumn}