Added recategorization from UI

This commit is contained in:
Manuel Forcén Muñoz 2024-05-16 23:08:56 +02:00
parent 128cd85a9b
commit 1ad1e66470
4 changed files with 25 additions and 12 deletions

View file

@ -63,15 +63,9 @@ impl Account {
Ok(res)
}
pub async fn recategorize_transactions(
&self,
pool: &SqlitePool,
from: Option<DateTime<Utc>>,
to: Option<DateTime<Utc>>,
) -> Result<()> {
pub async fn recategorize_transactions(&self, pool: &SqlitePool) -> Result<()> {
let rules = Rule::list_by_user(pool, self.user).await?;
let mut tx_list =
Transaction::list_by_date(pool, self.account_id, from, to, None, true).await?;
let mut tx_list = Transaction::list_uncategorized(pool, self.account_id).await?;
for tx in tx_list.iter_mut() {
println!("Checking {}", tx.get_description());
if tx.recategorize(pool, &rules).await? {

View file

@ -157,6 +157,20 @@ impl Transaction {
Ok(res)
}
pub async fn list_uncategorized(pool: &SqlitePool, account: i32) -> Result<Vec<Self>> {
let mut query = sqlx::QueryBuilder::new("SELECT * FROM TRANSACTIONS WHERE account=");
query.push_bind(account);
query.push(" AND category IS NULL");
let rows = query.build().fetch_all(pool).await?;
let mut ret = Vec::new();
for r in &rows {
ret.push(Transaction::from_row(r)?);
}
Ok(ret)
}
pub async fn group_by_date(
pool: &SqlitePool,
account: i32,