Adapts receivable/payable logic for Beancount
Modifies receivable and payable checks to align with Beancount's accounting principles. This adjustment ensures that the system correctly identifies receivables and payables based on the sign of the amounts, rather than just debit/credit. Also, calculates transaction sizes using the absolute value of amounts.
This commit is contained in:
parent
5cc2630777
commit
d0bec3ea5a
1 changed files with 11 additions and 7 deletions
|
|
@ -1419,7 +1419,9 @@ window.app = Vue.createApp({
|
||||||
},
|
},
|
||||||
getTotalAmount(entry) {
|
getTotalAmount(entry) {
|
||||||
if (!entry.lines || entry.lines.length === 0) return 0
|
if (!entry.lines || entry.lines.length === 0) return 0
|
||||||
return entry.lines.reduce((sum, line) => sum + line.debit + line.credit, 0) / 2
|
// Beancount-style: use absolute value of amounts
|
||||||
|
// All lines have amounts (positive or negative), we want the transaction size
|
||||||
|
return entry.lines.reduce((sum, line) => sum + Math.abs(line.amount || 0), 0) / 2
|
||||||
},
|
},
|
||||||
getEntryFiatAmount(entry) {
|
getEntryFiatAmount(entry) {
|
||||||
// Extract fiat amount from metadata if available
|
// Extract fiat amount from metadata if available
|
||||||
|
|
@ -1434,12 +1436,13 @@ window.app = Vue.createApp({
|
||||||
},
|
},
|
||||||
isReceivable(entry) {
|
isReceivable(entry) {
|
||||||
// Check if this is a receivable entry (user owes castle)
|
// Check if this is a receivable entry (user owes castle)
|
||||||
// Receivables have a debit to an "Accounts Receivable" account with the user's ID
|
// Receivables have a positive amount (debit) to an "Accounts Receivable" account
|
||||||
if (!entry.lines || entry.lines.length === 0) return false
|
if (!entry.lines || entry.lines.length === 0) return false
|
||||||
|
|
||||||
for (const line of entry.lines) {
|
for (const line of entry.lines) {
|
||||||
// Look for a line with positive debit on an accounts receivable account
|
// Look for a line with positive amount on an accounts receivable account
|
||||||
if (line.debit > 0) {
|
// Beancount-style: positive amount = debit (asset increase)
|
||||||
|
if (line.amount > 0) {
|
||||||
// Check if the account is associated with this user's receivables
|
// Check if the account is associated with this user's receivables
|
||||||
const account = this.accounts.find(a => a.id === line.account_id)
|
const account = this.accounts.find(a => a.id === line.account_id)
|
||||||
if (account && account.name && account.name.includes('Assets:Receivable') && account.account_type === 'asset') {
|
if (account && account.name && account.name.includes('Assets:Receivable') && account.account_type === 'asset') {
|
||||||
|
|
@ -1451,12 +1454,13 @@ window.app = Vue.createApp({
|
||||||
},
|
},
|
||||||
isPayable(entry) {
|
isPayable(entry) {
|
||||||
// Check if this is a payable entry (castle owes user)
|
// Check if this is a payable entry (castle owes user)
|
||||||
// Payables have a credit to an "Accounts Payable" account with the user's ID
|
// Payables have a negative amount (credit) to an "Accounts Payable" account
|
||||||
if (!entry.lines || entry.lines.length === 0) return false
|
if (!entry.lines || entry.lines.length === 0) return false
|
||||||
|
|
||||||
for (const line of entry.lines) {
|
for (const line of entry.lines) {
|
||||||
// Look for a line with positive credit on an accounts payable account
|
// Look for a line with negative amount on an accounts payable account
|
||||||
if (line.credit > 0) {
|
// Beancount-style: negative amount = credit (liability increase)
|
||||||
|
if (line.amount < 0) {
|
||||||
// Check if the account is associated with this user's payables
|
// Check if the account is associated with this user's payables
|
||||||
const account = this.accounts.find(a => a.id === line.account_id)
|
const account = this.accounts.find(a => a.id === line.account_id)
|
||||||
if (account && account.name && account.name.includes('Liabilities:Payable') && account.account_type === 'liability') {
|
if (account && account.name && account.name.includes('Liabilities:Payable') && account.account_type === 'liability') {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue