Skip to content

Commit

Permalink
Removed paid column. paid_amount is updated now
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Sep 20, 2024
1 parent 7486a33 commit bfbd9c3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down
66 changes: 21 additions & 45 deletions core/payment/src/dao/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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<String>,
Option<String>,
Option<String>,
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::<DbBatchOrderItem>(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::<DbBatchOrder>(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)
})
Expand Down
1 change: 0 additions & 1 deletion core/payment/src/models/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 0 additions & 1 deletion core/payment/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ table! {
platform -> Text,
total_amount -> Text,
paid_amount -> Text,
paid -> Bool,
}
}

Expand Down

0 comments on commit bfbd9c3

Please sign in to comment.