|
|
@ -6,7 +6,6 @@ import { useRef, useState } from "@odoo/owl"; |
|
|
import { BlockUI } from "@web/core/ui/block_ui"; |
|
|
import { BlockUI } from "@web/core/ui/block_ui"; |
|
|
import { download } from "@web/core/network/download"; |
|
|
import { download } from "@web/core/network/download"; |
|
|
const actionRegistry = registry.category("actions"); |
|
|
const actionRegistry = registry.category("actions"); |
|
|
|
|
|
|
|
|
class PartnerLedger extends owl.Component { |
|
|
class PartnerLedger extends owl.Component { |
|
|
setup() { |
|
|
setup() { |
|
|
super.setup(...arguments); |
|
|
super.setup(...arguments); |
|
|
@ -25,6 +24,8 @@ class PartnerLedger extends owl.Component { |
|
|
filter_applied: null, |
|
|
filter_applied: null, |
|
|
selected_partner: [], |
|
|
selected_partner: [], |
|
|
selected_partner_rec: [], |
|
|
selected_partner_rec: [], |
|
|
|
|
|
all_partners: [], |
|
|
|
|
|
filtered_partners: [], |
|
|
total_debit: null, |
|
|
total_debit: null, |
|
|
total_debit_display:null, |
|
|
total_debit_display:null, |
|
|
total_credit: null, |
|
|
total_credit: null, |
|
|
@ -34,10 +35,281 @@ class PartnerLedger extends owl.Component { |
|
|
account: null, |
|
|
account: null, |
|
|
options: null, |
|
|
options: null, |
|
|
message_list : [], |
|
|
message_list : [], |
|
|
|
|
|
selected_tags: [], |
|
|
|
|
|
selected_tag_ids: [], |
|
|
|
|
|
all_tags: [], |
|
|
|
|
|
filtered_tags: [], |
|
|
|
|
|
selected_accounts: [], |
|
|
|
|
|
selected_account_ids: [], |
|
|
|
|
|
all_accounts: [], |
|
|
|
|
|
filtered_accounts: [], |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
this.load_data(self.initial_render = true); |
|
|
this.load_data(self.initial_render = true); |
|
|
|
|
|
this.loadPartners(); |
|
|
|
|
|
this.loadTags(); |
|
|
|
|
|
this.loadAccounts(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async loadPartners() { |
|
|
|
|
|
/** |
|
|
|
|
|
* Loads all available partners from the database |
|
|
|
|
|
*/ |
|
|
|
|
|
try { |
|
|
|
|
|
const partners = await this.orm.searchRead( |
|
|
|
|
|
'res.partner', |
|
|
|
|
|
[], |
|
|
|
|
|
['id', 'name', 'display_name'], |
|
|
|
|
|
{ limit: 100 } |
|
|
|
|
|
); |
|
|
|
|
|
this.state.all_partners = partners; |
|
|
|
|
|
this.state.filtered_partners = partners; |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.error('Error loading partners:', error); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
searchPartners(ev) { |
|
|
|
|
|
/** |
|
|
|
|
|
* Filters the partner list based on search input |
|
|
|
|
|
* @param {Event} ev - The input event |
|
|
|
|
|
*/ |
|
|
|
|
|
const searchTerm = ev.target.value.toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
if (!searchTerm) { |
|
|
|
|
|
this.state.filtered_partners = this.state.all_partners; |
|
|
|
|
|
} else { |
|
|
|
|
|
this.state.filtered_partners = this.state.all_partners.filter(partner => { |
|
|
|
|
|
const name = (partner.display_name || partner.name || '').toLowerCase(); |
|
|
|
|
|
return name.includes(searchTerm); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
selectPartner(ev) { |
|
|
|
|
|
/** |
|
|
|
|
|
* Adds a partner to the selected list |
|
|
|
|
|
*/ |
|
|
|
|
|
ev.preventDefault(); |
|
|
|
|
|
ev.stopPropagation(); |
|
|
|
|
|
|
|
|
|
|
|
const partnerId = parseInt(ev.target.dataset.partnerId, 10); |
|
|
|
|
|
|
|
|
|
|
|
if (this.state.selected_partner.includes(partnerId)) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const partner = this.state.all_partners.find(p => p.id === partnerId); |
|
|
|
|
|
|
|
|
|
|
|
if (partner) { |
|
|
|
|
|
this.state.selected_partner.push(partnerId); |
|
|
|
|
|
this.state.selected_partner_rec.push(partner); |
|
|
|
|
|
this.applyAllFilters(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
removePartner(ev) { |
|
|
|
|
|
/** |
|
|
|
|
|
* Removes a partner from the selected list |
|
|
|
|
|
*/ |
|
|
|
|
|
ev.preventDefault(); |
|
|
|
|
|
ev.stopPropagation(); |
|
|
|
|
|
|
|
|
|
|
|
const partnerId = parseInt(ev.target.dataset.partnerId, 10); |
|
|
|
|
|
const partnerIndex = this.state.selected_partner.indexOf(partnerId); |
|
|
|
|
|
|
|
|
|
|
|
if (partnerIndex > -1) { |
|
|
|
|
|
this.state.selected_partner.splice(partnerIndex, 1); |
|
|
|
|
|
this.state.selected_partner_rec.splice(partnerIndex, 1); |
|
|
|
|
|
this.applyAllFilters(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clearAllPartners(ev) { |
|
|
|
|
|
/** |
|
|
|
|
|
* Clears all selected partners |
|
|
|
|
|
*/ |
|
|
|
|
|
ev.preventDefault(); |
|
|
|
|
|
ev.stopPropagation(); |
|
|
|
|
|
|
|
|
|
|
|
this.state.selected_partner = []; |
|
|
|
|
|
this.state.selected_partner_rec = []; |
|
|
|
|
|
this.applyAllFilters(); |
|
|
|
|
|
} |
|
|
|
|
|
// ==================== PARTNER TAGS METHODS ====================
|
|
|
|
|
|
async loadTags() { |
|
|
|
|
|
/** |
|
|
|
|
|
* Loads all partner tags (categories) from the database |
|
|
|
|
|
*/ |
|
|
|
|
|
try { |
|
|
|
|
|
const tags = await this.orm.searchRead( |
|
|
|
|
|
'res.partner.category', |
|
|
|
|
|
[], |
|
|
|
|
|
['id', 'name'], |
|
|
|
|
|
{ limit: 200, order: 'name' } |
|
|
|
|
|
); |
|
|
|
|
|
this.state.all_tags = tags; |
|
|
|
|
|
this.state.filtered_tags = tags; |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.error('Error loading tags:', error); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
searchTags(ev) { |
|
|
|
|
|
/** |
|
|
|
|
|
* Filters the tag list based on search input |
|
|
|
|
|
*/ |
|
|
|
|
|
const searchTerm = ev.target.value.toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
if (!searchTerm) { |
|
|
|
|
|
this.state.filtered_tags = this.state.all_tags; |
|
|
|
|
|
} else { |
|
|
|
|
|
this.state.filtered_tags = this.state.all_tags.filter(tag => { |
|
|
|
|
|
const name = (tag.name || '').toLowerCase(); |
|
|
|
|
|
return name.includes(searchTerm); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
selectTag(ev) { |
|
|
|
|
|
/** |
|
|
|
|
|
* Adds a tag to the selected list |
|
|
|
|
|
*/ |
|
|
|
|
|
ev.preventDefault(); |
|
|
|
|
|
ev.stopPropagation(); |
|
|
|
|
|
|
|
|
|
|
|
const tagId = parseInt(ev.target.dataset.tagId, 10); |
|
|
|
|
|
|
|
|
|
|
|
if (this.state.selected_tag_ids.includes(tagId)) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const tag = this.state.all_tags.find(t => t.id === tagId); |
|
|
|
|
|
|
|
|
|
|
|
if (tag) { |
|
|
|
|
|
this.state.selected_tag_ids.push(tagId); |
|
|
|
|
|
this.state.selected_tags.push(tag); |
|
|
|
|
|
this.applyAllFilters(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
removeTag(ev) { |
|
|
|
|
|
/** |
|
|
|
|
|
* Removes a tag from the selected list |
|
|
|
|
|
*/ |
|
|
|
|
|
ev.preventDefault(); |
|
|
|
|
|
ev.stopPropagation(); |
|
|
|
|
|
|
|
|
|
|
|
const tagId = parseInt(ev.target.dataset.tagId, 10); |
|
|
|
|
|
const tagIndex = this.state.selected_tag_ids.indexOf(tagId); |
|
|
|
|
|
|
|
|
|
|
|
if (tagIndex > -1) { |
|
|
|
|
|
this.state.selected_tag_ids.splice(tagIndex, 1); |
|
|
|
|
|
this.state.selected_tags.splice(tagIndex, 1); |
|
|
|
|
|
this.applyAllFilters(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clearAllTags(ev) { |
|
|
|
|
|
/** |
|
|
|
|
|
* Clears all selected tags |
|
|
|
|
|
*/ |
|
|
|
|
|
ev.preventDefault(); |
|
|
|
|
|
ev.stopPropagation(); |
|
|
|
|
|
|
|
|
|
|
|
this.state.selected_tag_ids = []; |
|
|
|
|
|
this.state.selected_tags = []; |
|
|
|
|
|
this.applyAllFilters(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ==================== ACCOUNTS METHODS ====================
|
|
|
|
|
|
async loadAccounts() { |
|
|
|
|
|
/** |
|
|
|
|
|
* Loads all accounts from the database |
|
|
|
|
|
*/ |
|
|
|
|
|
try { |
|
|
|
|
|
const accounts = await this.orm.searchRead( |
|
|
|
|
|
'account.account', |
|
|
|
|
|
[], |
|
|
|
|
|
['id', 'code', 'name'], |
|
|
|
|
|
{ limit: 500, order: 'code' } |
|
|
|
|
|
); |
|
|
|
|
|
this.state.all_accounts = accounts; |
|
|
|
|
|
this.state.filtered_accounts = accounts; |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.error('Error loading accounts:', error); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
searchAccounts(ev) { |
|
|
|
|
|
/** |
|
|
|
|
|
* Filters the account list based on search input |
|
|
|
|
|
*/ |
|
|
|
|
|
const searchTerm = ev.target.value.toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
if (!searchTerm) { |
|
|
|
|
|
this.state.filtered_accounts = this.state.all_accounts; |
|
|
|
|
|
} else { |
|
|
|
|
|
this.state.filtered_accounts = this.state.all_accounts.filter(account => { |
|
|
|
|
|
const code = (account.code || '').toLowerCase(); |
|
|
|
|
|
const name = (account.name || '').toLowerCase(); |
|
|
|
|
|
return code.includes(searchTerm) || name.includes(searchTerm); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
selectAccount(ev) { |
|
|
|
|
|
/** |
|
|
|
|
|
* Adds an account to the selected list |
|
|
|
|
|
*/ |
|
|
|
|
|
ev.preventDefault(); |
|
|
|
|
|
ev.stopPropagation(); |
|
|
|
|
|
|
|
|
|
|
|
const accountId = parseInt(ev.target.dataset.accountId, 10); |
|
|
|
|
|
|
|
|
|
|
|
if (this.state.selected_account_ids.includes(accountId)) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const account = this.state.all_accounts.find(a => a.id === accountId); |
|
|
|
|
|
|
|
|
|
|
|
if (account) { |
|
|
|
|
|
this.state.selected_account_ids.push(accountId); |
|
|
|
|
|
this.state.selected_accounts.push(account); |
|
|
|
|
|
this.applyAllFilters(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
removeAccount(ev) { |
|
|
|
|
|
/** |
|
|
|
|
|
* Removes an account from the selected list |
|
|
|
|
|
*/ |
|
|
|
|
|
ev.preventDefault(); |
|
|
|
|
|
ev.stopPropagation(); |
|
|
|
|
|
|
|
|
|
|
|
const accountId = parseInt(ev.target.dataset.accountId, 10); |
|
|
|
|
|
const accountIndex = this.state.selected_account_ids.indexOf(accountId); |
|
|
|
|
|
|
|
|
|
|
|
if (accountIndex > -1) { |
|
|
|
|
|
this.state.selected_account_ids.splice(accountIndex, 1); |
|
|
|
|
|
this.state.selected_accounts.splice(accountIndex, 1); |
|
|
|
|
|
this.applyAllFilters(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clearAllAccounts(ev) { |
|
|
|
|
|
/** |
|
|
|
|
|
* Clears all selected accounts |
|
|
|
|
|
*/ |
|
|
|
|
|
ev.preventDefault(); |
|
|
|
|
|
ev.stopPropagation(); |
|
|
|
|
|
|
|
|
|
|
|
this.state.selected_account_ids = []; |
|
|
|
|
|
this.state.selected_accounts = []; |
|
|
|
|
|
this.applyAllFilters(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
formatNumberWithSeparators(number) { |
|
|
formatNumberWithSeparators(number) { |
|
|
const parsedNumber = parseFloat(number); |
|
|
const parsedNumber = parseFloat(number); |
|
|
if (isNaN(parsedNumber)) { |
|
|
if (isNaN(parsedNumber)) { |
|
|
@ -274,14 +546,19 @@ class PartnerLedger extends owl.Component { |
|
|
target: "current", |
|
|
target: "current", |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async applyFilter(val, ev, is_delete = false) { |
|
|
async applyFilter(val, ev, is_delete = false) { |
|
|
/** |
|
|
/** |
|
|
* Applies filters to the partner ledger report based on the provided values. |
|
|
* Applies filters to the partner ledger report based on the provided values. |
|
|
* |
|
|
* This method handles date ranges, account types, and options filters. |
|
|
* @param {any} val - The value of the filter. |
|
|
* Partner, tag, and account filters are handled by their respective methods. |
|
|
* @param {Event} ev - The event object triggered by the action. |
|
|
* |
|
|
* @param {boolean} is_delete - Indicates whether the filter value is being deleted. |
|
|
* @param {any} val - The value of the filter. |
|
|
*/ |
|
|
* @param {Event} ev - The event object triggered by the action (can be null). |
|
|
|
|
|
* @param {boolean} is_delete - Indicates whether the filter value is being deleted. |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
// Handle date range and other button-based filters
|
|
|
let partner_list = [] |
|
|
let partner_list = [] |
|
|
let partner_value = [] |
|
|
let partner_value = [] |
|
|
let partner_totals = '' |
|
|
let partner_totals = '' |
|
|
@ -292,109 +569,147 @@ class PartnerLedger extends owl.Component { |
|
|
this.state.filter_applied = true; |
|
|
this.state.filter_applied = true; |
|
|
let totalDebitSum = 0; |
|
|
let totalDebitSum = 0; |
|
|
let totalCreditSum = 0; |
|
|
let totalCreditSum = 0; |
|
|
if (ev) { |
|
|
if (val && val.target) { |
|
|
if (ev.input && ev.input.attributes.placeholder.value == 'Partner' && !is_delete) { |
|
|
const target = val.target; |
|
|
this.state.selected_partner.push(val[0].id) |
|
|
|
|
|
this.state.selected_partner_rec.push(val[0]) |
|
|
if (target.name === 'start_date') { |
|
|
} else if (is_delete) { |
|
|
|
|
|
let index = this.state.selected_partner_rec.indexOf(val) |
|
|
|
|
|
this.state.selected_partner_rec.splice(index, 1) |
|
|
|
|
|
this.state.selected_partner = this.state.selected_partner_rec.map((rec) => rec.id) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if (val.target.name === 'start_date') { |
|
|
|
|
|
this.state.date_range = { |
|
|
this.state.date_range = { |
|
|
...this.state.date_range, |
|
|
...this.state.date_range, |
|
|
start_date: val.target.value |
|
|
start_date: target.value |
|
|
}; |
|
|
}; |
|
|
} else if (val.target.name === 'end_date') { |
|
|
} else if (target.name === 'end_date') { |
|
|
this.state.date_range = { |
|
|
this.state.date_range = { |
|
|
...this.state.date_range, |
|
|
...this.state.date_range, |
|
|
end_date: val.target.value |
|
|
end_date: target.value |
|
|
}; |
|
|
}; |
|
|
} else if (val.target.attributes["data-value"].value == 'month') { |
|
|
} else if (target.attributes["data-value"]) { |
|
|
this.state.date_range = val.target.attributes["data-value"].value |
|
|
const dataValue = target.attributes["data-value"].value; |
|
|
} else if (val.target.attributes["data-value"].value == 'year') { |
|
|
|
|
|
this.state.date_range = val.target.attributes["data-value"].value |
|
|
// Handle date range presets
|
|
|
} else if (val.target.attributes["data-value"].value == 'quarter') { |
|
|
if (['month', 'year', 'quarter', 'last-month', 'last-year', 'last-quarter'].includes(dataValue)) { |
|
|
this.state.date_range = val.target.attributes["data-value"].value |
|
|
this.state.date_range = dataValue; |
|
|
} else if (val.target.attributes["data-value"].value == 'last-month') { |
|
|
|
|
|
this.state.date_range = val.target.attributes["data-value"].value |
|
|
|
|
|
} else if (val.target.attributes["data-value"].value == 'last-year') { |
|
|
|
|
|
this.state.date_range = val.target.attributes["data-value"].value |
|
|
|
|
|
} else if (val.target.attributes["data-value"].value == 'last-quarter') { |
|
|
|
|
|
this.state.date_range = val.target.attributes["data-value"].value |
|
|
|
|
|
} else if (val.target.attributes["data-value"].value === 'receivable') { |
|
|
|
|
|
// Check if the target has 'selected-filter' class
|
|
|
|
|
|
if (val.target.classList.contains("selected-filter")) { |
|
|
|
|
|
// Remove 'receivable' key from account
|
|
|
|
|
|
const { Receivable, ...updatedAccount } = this.state.account; |
|
|
|
|
|
this.state.account = updatedAccount; |
|
|
|
|
|
val.target.classList.remove("selected-filter"); |
|
|
|
|
|
} else { |
|
|
|
|
|
// Update receivable property in account
|
|
|
|
|
|
this.state.account = { |
|
|
|
|
|
...this.state.account, |
|
|
|
|
|
'Receivable': true |
|
|
|
|
|
}; |
|
|
|
|
|
val.target.classList.add("selected-filter"); // Add class "selected-filter"
|
|
|
|
|
|
} |
|
|
} |
|
|
} else if (val.target.attributes["data-value"].value === 'payable') { |
|
|
// Handle account types (Receivable/Payable)
|
|
|
// Check if the target has 'selected-filter' class
|
|
|
else if (dataValue === 'receivable') { |
|
|
if (val.target.classList.contains("selected-filter")) { |
|
|
if (target.classList.contains("selected-filter")) { |
|
|
// Remove 'receivable' key from account
|
|
|
const { Receivable, ...updatedAccount } = this.state.account || {}; |
|
|
const { Payable, ...updatedAccount } = this.state.account; |
|
|
this.state.account = updatedAccount; |
|
|
this.state.account = updatedAccount; |
|
|
target.classList.remove("selected-filter"); |
|
|
val.target.classList.remove("selected-filter"); |
|
|
} else { |
|
|
} else { |
|
|
this.state.account = { |
|
|
// Update receivable property in account
|
|
|
...this.state.account, |
|
|
this.state.account = { |
|
|
'Receivable': true |
|
|
...this.state.account, |
|
|
}; |
|
|
'Payable': true |
|
|
target.classList.add("selected-filter"); |
|
|
}; |
|
|
} |
|
|
val.target.classList.add("selected-filter"); // Add class "selected-filter"
|
|
|
} else if (dataValue === 'payable') { |
|
|
|
|
|
if (target.classList.contains("selected-filter")) { |
|
|
|
|
|
const { Payable, ...updatedAccount } = this.state.account || {}; |
|
|
|
|
|
this.state.account = updatedAccount; |
|
|
|
|
|
target.classList.remove("selected-filter"); |
|
|
|
|
|
} else { |
|
|
|
|
|
this.state.account = { |
|
|
|
|
|
...this.state.account, |
|
|
|
|
|
'Payable': true |
|
|
|
|
|
}; |
|
|
|
|
|
target.classList.add("selected-filter"); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} else if (val.target.attributes["data-value"].value === 'draft') { |
|
|
// Handle options (Draft entries, etc.)
|
|
|
// Check if the target has 'selected-filter' class
|
|
|
else if (dataValue === 'draft') { |
|
|
if (val.target.classList.contains("selected-filter")) { |
|
|
if (target.classList.contains("selected-filter")) { |
|
|
// Remove 'receivable' key from account
|
|
|
const { draft, ...updatedOptions } = this.state.options || {}; |
|
|
const { draft, ...updatedAccount } = this.state.options; |
|
|
this.state.options = updatedOptions; |
|
|
this.state.options = updatedAccount; |
|
|
target.classList.remove("selected-filter"); |
|
|
val.target.classList.remove("selected-filter"); |
|
|
} else { |
|
|
} else { |
|
|
this.state.options = { |
|
|
// Update receivable property in account
|
|
|
...this.state.options, |
|
|
this.state.options = { |
|
|
'draft': true |
|
|
...this.state.options, |
|
|
}; |
|
|
'draft': true |
|
|
target.classList.add("selected-filter"); |
|
|
}; |
|
|
} |
|
|
val.target.classList.add("selected-filter"); // Add class "selected-filter"
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Apply all filters after any change
|
|
|
|
|
|
await this.applyAllFilters(); |
|
|
} |
|
|
} |
|
|
let filtered_data = await this.orm.call("account.partner.ledger", "get_filter_values", [this.state.selected_partner, this.state.date_range, this.state.account, this.state.options,]); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async applyAllFilters() { |
|
|
|
|
|
/** |
|
|
|
|
|
* Applies all selected filters (partners, tags, accounts, date range, etc.) |
|
|
|
|
|
*/ |
|
|
|
|
|
this.state.partners = null; |
|
|
|
|
|
this.state.data = null; |
|
|
|
|
|
this.state.total = null; |
|
|
|
|
|
this.state.filter_applied = true; |
|
|
|
|
|
|
|
|
|
|
|
let totalDebitSum = 0; |
|
|
|
|
|
let totalCreditSum = 0; |
|
|
|
|
|
let partner_list = []; |
|
|
|
|
|
let partner_totals = ''; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// Call backend with all filter parameters
|
|
|
|
|
|
let filtered_data = await this.orm.call( |
|
|
|
|
|
"account.partner.ledger", |
|
|
|
|
|
"get_filter_values", |
|
|
|
|
|
[ |
|
|
|
|
|
this.state.selected_partner, // partner IDs
|
|
|
|
|
|
this.state.date_range, // date range
|
|
|
|
|
|
this.state.account, // account type (receivable/payable)
|
|
|
|
|
|
this.state.options, // options (draft entries, etc.)
|
|
|
|
|
|
this.state.selected_tag_ids, // partner tag IDs
|
|
|
|
|
|
this.state.selected_account_ids // account IDs
|
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
// Process filtered data
|
|
|
for (let index in filtered_data) { |
|
|
for (let index in filtered_data) { |
|
|
const value = filtered_data[index]; |
|
|
const value = filtered_data[index]; |
|
|
if (index !== 'partner_totals') { |
|
|
if (index !== 'partner_totals') { |
|
|
partner_list.push(index) |
|
|
partner_list.push(index); |
|
|
} |
|
|
} else { |
|
|
else { |
|
|
partner_totals = value; |
|
|
partner_totals = value |
|
|
Object.values(partner_totals).forEach(partner_data => { |
|
|
Object.values(partner_totals).forEach(partner_list => { |
|
|
totalDebitSum += partner_data.total_debit || 0; |
|
|
totalDebitSum += partner_list.total_debit || 0; |
|
|
totalCreditSum += partner_data.total_credit || 0; |
|
|
totalCreditSum += partner_list.total_credit || 0; |
|
|
partner_data.total_debit_display = this.formatNumberWithSeparators(partner_data.total_debit || 0); |
|
|
}); |
|
|
partner_data.total_credit_display = this.formatNumberWithSeparators(partner_data.total_credit || 0); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
this.state.partners = partner_list |
|
|
|
|
|
this.state.data = filtered_data |
|
|
// Format entries
|
|
|
this.state.total = partner_totals |
|
|
Object.entries(filtered_data).forEach(([key, value]) => { |
|
|
this.state.total_debit = totalDebitSum |
|
|
if (key !== 'partner_totals') { |
|
|
this.state.total_credit = totalCreditSum |
|
|
value.forEach(entry => { |
|
|
if (this.unfoldButton.el.classList.contains("selected-filter")) { |
|
|
entry[0].debit_display = this.formatNumberWithSeparators(entry[0].debit || 0); |
|
|
|
|
|
entry[0].credit_display = this.formatNumberWithSeparators(entry[0].credit || 0); |
|
|
|
|
|
entry[0].amount_currency_display = this.formatNumberWithSeparators(entry[0].amount_currency || 0); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Update state
|
|
|
|
|
|
this.state.partners = partner_list; |
|
|
|
|
|
this.state.data = filtered_data; |
|
|
|
|
|
this.state.total = partner_totals; |
|
|
|
|
|
this.state.total_debit = totalDebitSum; |
|
|
|
|
|
this.state.total_debit_display = this.formatNumberWithSeparators(totalDebitSum); |
|
|
|
|
|
this.state.total_credit = totalCreditSum; |
|
|
|
|
|
this.state.total_credit_display = this.formatNumberWithSeparators(totalCreditSum); |
|
|
|
|
|
|
|
|
|
|
|
if (this.unfoldButton.el && this.unfoldButton.el.classList.contains("selected-filter")) { |
|
|
this.unfoldButton.el.classList.remove("selected-filter"); |
|
|
this.unfoldButton.el.classList.remove("selected-filter"); |
|
|
} |
|
|
} |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.error('Error applying filters:', error); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getDomain() { |
|
|
getDomain() { |
|
|
return []; |
|
|
return []; |
|
|
} |
|
|
} |
|
|
|