Skip to content

Commit

Permalink
payment: Only generate payment events for payable debit notes
Browse files Browse the repository at this point in the history
  • Loading branch information
kamirr committed Nov 13, 2023
1 parent 2a83376 commit d4321e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions core/payment/src/dao/debit_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ impl<'c> DebitNoteDao<'c> {
&self,
role: Option<Role>,
status: Option<DocumentStatus>,
payable: Option<bool>,
) -> DbResult<Vec<DebitNote>> {
readonly_transaction(self.pool, move |conn| {
let mut query = query!().into_boxed();
Expand All @@ -212,6 +213,14 @@ impl<'c> DebitNoteDao<'c> {
if let Some(status) = status {
query = query.filter(dsl::status.eq(status.to_string()));
}
if let Some(payable) = payable {
// Payable debit notes have not-null payment_due_date.
if payable {
query = query.filter(dsl::payment_due_date.is_not_null());
} else {
query = query.filter(dsl::payment_due_date.is_null());
}
}

let debit_notes: Vec<ReadObj> = query.order_by(dsl::timestamp.desc()).load(conn)?;
debit_notes.into_iter().map(TryInto::try_into).collect()
Expand Down
6 changes: 5 additions & 1 deletion core/payment/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,11 @@ mod public {
let invoice_ev_dao: InvoiceEventDao = db.as_dao();

let accepted_notes = debit_note_dao
.list(Some(Role::Requestor), Some(DocumentStatus::Accepted))
.list(
Some(Role::Requestor),
Some(DocumentStatus::Accepted),
Some(true),
)
.await
.map_err(GenericError::new)?;

Expand Down

0 comments on commit d4321e8

Please sign in to comment.