fix(paheko): transaction reference can be NULL

This commit is contained in:
Matthieu Bessat 2024-01-21 23:22:03 +01:00
parent f8a5aac75f
commit 6ae274e810
3 changed files with 10 additions and 9 deletions

View file

@ -95,7 +95,7 @@ struct SimpleTransaction {
amount: f64,
credit_account_code: String,
debit_account_code: String,
reference: String,
reference: Option<String>,
linked_users: Vec<Id>,
linked_subscriptions: Vec<Id>,
accounting_year: Id
@ -321,7 +321,7 @@ impl AuthentifiedClient {
#[allow(dead_code)]
id: u64,
label: String,
reference: String,
reference: Option<String>,
#[serde(deserialize_with = "deserialize_json_list")]
accounts_codes: Vec<String>,
year_id: u64,
@ -545,9 +545,11 @@ impl AuthentifiedClient {
.text("debit", transaction.debit_account_code)
.text("credit", transaction.credit_account_code)
// "Numéro pièce comptable" enregistré au niveau de la transaction
.text("reference", transaction.reference)
;
if let Some(reference) = transaction.reference {
form = form.text("reference", reference);
}
for linked_id in transaction.linked_users {
form = form.text("linked_users[]", format!("{}", linked_id.0));
}

View file

@ -30,7 +30,7 @@ async fn get_auth_client_from_cache(
Ok(auth_client)
}
eprintln!("Init HA client");
eprintln!("Initializing HA client");
match &user_cache.helloasso_session {
Some(cached_session) => {
@ -97,8 +97,6 @@ pub async fn sync_helloasso(
user_cache: &mut UserCache,
dry_run: bool
) -> Result<()> {
eprintln!("wow");
let mut ha_client: helloasso::Client = helloasso::Client::new(helloasso::ClientConfig {
base_url: Url::parse("https://api.helloasso.com/v5/")
.expect("Expected valid helloasso API base URL"),

View file

@ -112,7 +112,7 @@ pub async fn sync_paheko(
let existing_matching_transactions: Vec<&SimpleTransaction> = existing_transactions
.iter()
.filter(|t| t.reference == answer.reference)
.filter(|t| t.reference == Some(answer.reference.clone()))
.collect();
// check for existing user in paheko by email
@ -123,6 +123,7 @@ pub async fn sync_paheko(
let pk_user_summary = match existing_user_opt.clone() {
Some(user) => {
eprintln!(" Found existing paheko user by matching name.");
// TODO: if existing user is different, update the details of user
user
},
None => {
@ -233,7 +234,7 @@ pub async fn sync_paheko(
// TODO: make the label template configurable
label: format!("{} {:?} via {}", pk_membership.service_name, pk_membership.mode_name, via_name),
amount: pk_membership.payed_amount,
reference: answer.reference.clone(),
reference: Some(answer.reference.clone()),
credit_account_code: "756".to_string(), // cotisations account
debit_account_code: debit_account_code.to_string(), // helloasso account
inception_time: answer.inception_time,
@ -264,7 +265,7 @@ pub async fn sync_paheko(
}.id.clone(),
label: format!("Don lié à une adhésion via {}", via_name),
amount: answer.donation_amount,
reference: answer.reference.clone(),
reference: Some(answer.reference.clone()),
credit_account_code: DONATION_ACCOUNT_CODE.to_string(), // account 754 - Ressources liées à la générosité du public
debit_account_code: debit_account_code.to_string(), // compte d'encaissement
inception_time: answer.inception_time,