diff --git a/core/payment/migrations/2024-08-12-171012_extended_order/up.sql b/core/payment/migrations/2024-08-12-171012_extended_order/up.sql index 574e860a3..397cd36f8 100644 --- a/core/payment/migrations/2024-08-12-171012_extended_order/up.sql +++ b/core/payment/migrations/2024-08-12-171012_extended_order/up.sql @@ -9,7 +9,6 @@ CREATE TABLE pay_batch_order( platform VARCHAR(50) NOT NULL, total_amount VARCHAR(32) NOT NULL, paid_amount VARCHAR(32) NOT NULL, - paid BOOLEAN NOT NULL DEFAULT FALSE, CONSTRAINT pay_batch_order_pk PRIMARY KEY(owner_id, id) ); diff --git a/core/payment/src/dao/batch.rs b/core/payment/src/dao/batch.rs index 2ecd603c2..2a4d7b747 100644 --- a/core/payment/src/dao/batch.rs +++ b/core/payment/src/dao/batch.rs @@ -946,7 +946,8 @@ impl<'c> BatchDao<'c> { oidsl::order_id .eq(&order_id) .and(oidsl::payee_addr.eq(&payee_addr)) - .and(oidsl::allocation_id.eq(allocation_id)) + .and(oidsl::allocation_id.eq(allocation_id.clone())) + .and(oidsl::owner_id.eq(owner_id)) .and(oidsl::paid.eq(false)), ) .set(oidsl::paid.eq(true)) @@ -958,52 +959,27 @@ impl<'c> BatchDao<'c> { return Err(DbError::Integrity("More than 1 rows updated".to_string())); } - /* - let query = d::pay_batch_order_item_document + let current_order_item = oidsl::pay_batch_order_item .filter( - d::order_id.eq(&order_id).and( - d::payee_addr - .eq(&payee_addr) - .and(d::owner_id.eq(&order.owner_id)), - ), + oidsl::order_id + .eq(&order_id) + .and(oidsl::payee_addr.eq(&payee_addr)) + .and(oidsl::allocation_id.eq(allocation_id)) + .and(oidsl::owner_id.eq(owner_id)), ) - .select(( - d::payee_addr, - d::agreement_id, - d::invoice_id, - d::activity_id, - d::debit_note_id, - d::amount, - )) - .load::<( - NodeId, - String, - Option, - Option, - Option, - BigDecimalField, - )>(conn)?; - for (payee_id, agreement_id, invoice_id, activity_id, _debit_note_id, amount) in query { - if let Some(activity_id) = activity_id { - log::warn!( - "Increasing amount paid for activity {} {}", - activity_id, - amount - ); - super::activity::increase_amount_paid( - &activity_id, - &order.owner_id, - &amount, - conn, - )?; - } - super::agreement::increase_amount_paid( - &agreement_id, - &order.owner_id, - &amount, - conn, - )?; - }*/ + .first::(conn)?; + + //update amount paid on batch order + let current_order = dsl::pay_batch_order + .filter(dsl::id.eq(&order_id).and(dsl::owner_id.eq(owner_id))) + .get_result::(conn)?; + + let updated_amount = current_order.paid_amount + current_order_item.amount; + + diesel::update(dsl::pay_batch_order) + .filter(dsl::id.eq(&order_id).and(dsl::owner_id.eq(owner_id))) + .set(dsl::paid_amount.eq(updated_amount)) + .execute(conn)?; Ok(true) }) diff --git a/core/payment/src/models/batch.rs b/core/payment/src/models/batch.rs index 41833a0a6..74b3271d2 100644 --- a/core/payment/src/models/batch.rs +++ b/core/payment/src/models/batch.rs @@ -69,7 +69,6 @@ pub struct DbBatchOrder { pub platform: String, pub total_amount: BigDecimalField, pub paid_amount: BigDecimalField, - pub paid: bool, } #[derive(Queryable, Debug, Serialize, Insertable)] diff --git a/core/payment/src/schema.rs b/core/payment/src/schema.rs index 1a31f67f2..2c2da5af3 100644 --- a/core/payment/src/schema.rs +++ b/core/payment/src/schema.rs @@ -84,7 +84,6 @@ table! { platform -> Text, total_amount -> Text, paid_amount -> Text, - paid -> Bool, } }