Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6455 cancelled prescription status #6509

Merged
merged 10 commits into from
Feb 13, 2025
1 change: 1 addition & 0 deletions client/packages/common/src/intl/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@
"label.variants": "Variants",
"label.ven": "VEN",
"label.verified": "Verified",
"label.cancelled": "Cancelled",
"label.visit-date": "Visit Date",
"label.visit-end": "End",
"label.visit-notes": "Notes",
Expand Down
2 changes: 2 additions & 0 deletions client/packages/common/src/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export enum ActivityLogNodeType {
InvoiceStatusVerified = 'INVOICE_STATUS_VERIFIED',
PrescriptionCreated = 'PRESCRIPTION_CREATED',
PrescriptionDeleted = 'PRESCRIPTION_DELETED',
PrescriptionStatusCancelled = 'PRESCRIPTION_STATUS_CANCELLED',
PrescriptionStatusPicked = 'PRESCRIPTION_STATUS_PICKED',
PrescriptionStatusVerified = 'PRESCRIPTION_STATUS_VERIFIED',
ProgramCreated = 'PROGRAM_CREATED',
Expand Down Expand Up @@ -3549,6 +3550,7 @@ export enum InvoiceNodeStatus {
* Inbound Shipment: not applicable
*/
Allocated = 'ALLOCATED',
Cancelled = 'CANCELLED',
/**
* General description: Inbound Shipment was received
* Outbound Shipment: Status is updated based on corresponding inbound Shipment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const createStatusLog = (invoice: InboundFragment) => {
[InvoiceNodeStatus.Verified]: null,
// Placeholder for typescript, not used in inbounds
[InvoiceNodeStatus.Allocated]: null,
[InvoiceNodeStatus.Cancelled]: null,
};

if (statusIdx >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const createStatusLog = (invoice: OutboundFragment) => {
[InvoiceNodeStatus.Shipped]: null,
[InvoiceNodeStatus.Delivered]: null,
[InvoiceNodeStatus.Verified]: null,
[InvoiceNodeStatus.Cancelled]: null,
};

if (statusIdx >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const createStatusLog = (invoice: PrescriptionRowFragment) => {
[InvoiceNodeStatus.Allocated]: null,
[InvoiceNodeStatus.Shipped]: null,
[InvoiceNodeStatus.Delivered]: null,
[InvoiceNodeStatus.Cancelled]: null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  if (statusIdx >= 3) {
    statusLog[InvoiceNodeStatus.Cancelled] = invoice.cancelledDatetime;
  }

We might want something like this added, I think that will require chaging the PrescriptionRowFragment as well though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an issue follow up on this...

};

if (statusIdx >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const createStatusLog = (invoice: CustomerReturnFragment) => {
[InvoiceNodeStatus.Verified]: null,
// Not used for returns
[InvoiceNodeStatus.Allocated]: null,
[InvoiceNodeStatus.Cancelled]: null,
};
if (statusIdx >= 0) {
statusLog[InvoiceNodeStatus.New] = invoice.createdDatetime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const createStatusLog = (invoice: SupplierReturnRowFragment) => {
[InvoiceNodeStatus.Verified]: null,
// Not used for Supplier return
[InvoiceNodeStatus.Allocated]: null,
[InvoiceNodeStatus.Cancelled]: null,
};
if (statusIdx >= 0) {
statusLog[InvoiceNodeStatus.New] = invoice.createdDatetime;
Expand Down
3 changes: 3 additions & 0 deletions client/packages/invoices/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const prescriptionStatuses: InvoiceNodeStatus[] = [
InvoiceNodeStatus.New,
InvoiceNodeStatus.Picked,
InvoiceNodeStatus.Verified,
InvoiceNodeStatus.Cancelled,
];

export const supplierReturnStatuses: InvoiceNodeStatus[] = [
Expand Down Expand Up @@ -85,6 +86,7 @@ const statusTranslation: Record<InvoiceNodeStatus, LocaleKey> = {
DELIVERED: 'label.delivered',
NEW: 'label.new',
VERIFIED: 'label.verified',
CANCELLED: 'label.cancelled',
};

export const getStatusTranslation = (status: InvoiceNodeStatus): LocaleKey => {
Expand Down Expand Up @@ -184,6 +186,7 @@ export const isInboundDisabled = (inbound: InboundRowFragment): boolean => {
case InvoiceNodeStatus.Allocated:
// Inbound shipments can be edited when having been delivered
case InvoiceNodeStatus.Delivered:
case InvoiceNodeStatus.Cancelled:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be in the disabled section, after Verified

return false;
case InvoiceNodeStatus.Picked:
case InvoiceNodeStatus.Shipped:
Expand Down
3 changes: 3 additions & 0 deletions server/graphql/types/src/types/activity_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub enum ActivityLogNodeType {
PrescriptionDeleted,
PrescriptionStatusPicked,
PrescriptionStatusVerified,
PrescriptionStatusCancelled,
SensorLocationChanged,
AssetCreated,
AssetUpdated,
Expand Down Expand Up @@ -213,6 +214,7 @@ impl ActivityLogNodeType {
from::DemographicIndicatorUpdated => to::DemographicIndicatorUpdated,
from::DemographicProjectionCreated => to::DemographicProjectionCreated,
from::DemographicProjectionUpdated => to::DemographicProjectionUpdated,
&repository::ActivityLogType::InvoiceStatusCancelled | &repository::ActivityLogType::PrescriptionStatusCancelled => todo!()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really want to have todo! code in the develop branch, will push a fix for this, mapping to the right fields.

            from::PrescriptionStatusCancelled => to::PrescriptionStatusCancelled,
            from::InvoiceStatusCancelled => to::InvoiceStatusCancelled,

}
}

Expand Down Expand Up @@ -277,6 +279,7 @@ impl ActivityLogNodeType {
from::DemographicIndicatorUpdated => to::DemographicIndicatorUpdated,
from::DemographicProjectionCreated => to::DemographicProjectionCreated,
from::DemographicProjectionUpdated => to::DemographicProjectionUpdated,
from::PrescriptionStatusCancelled => to::PrescriptionStatusCancelled,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions server/graphql/types/src/types/invoice_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub enum InvoiceNodeStatus {
/// Outbound Shipment: Status is updated based on corresponding inbound Shipment
/// Inbound Shipment: Becomes not editable
Verified,
// TODO: does further clarification need added for the cancelled status?
Cancelled,
}

pub struct InvoiceNode {
Expand Down Expand Up @@ -513,6 +515,7 @@ impl InvoiceNodeStatus {
Shipped => InvoiceStatus::Shipped,
Delivered => InvoiceStatus::Delivered,
Verified => InvoiceStatus::Verified,
Cancelled => InvoiceStatus::Cancelled,
}
}

Expand All @@ -525,6 +528,7 @@ impl InvoiceNodeStatus {
Shipped => InvoiceNodeStatus::Shipped,
Delivered => InvoiceNodeStatus::Delivered,
Verified => InvoiceNodeStatus::Verified,
Cancelled => InvoiceNodeStatus::Cancelled,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions server/repository/src/db_diesel/activity_log_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub enum ActivityLogType {
InvoiceStatusShipped,
InvoiceStatusDelivered,
InvoiceStatusVerified,
InvoiceStatusCancelled,
InventoryAdjustment,
StocktakeCreated,
StocktakeDeleted,
Expand All @@ -60,6 +61,7 @@ pub enum ActivityLogType {
PrescriptionDeleted,
PrescriptionStatusPicked,
PrescriptionStatusVerified,
PrescriptionStatusCancelled,
SensorLocationChanged,
AssetCreated,
AssetUpdated,
Expand Down
1 change: 1 addition & 0 deletions server/repository/src/db_diesel/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ impl InvoiceStatus {
InvoiceStatus::Shipped => 4,
InvoiceStatus::Delivered => 5,
InvoiceStatus::Verified => 6,
InvoiceStatus::Cancelled => 7,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions server/repository/src/db_diesel/invoice_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub enum InvoiceStatus {
Shipped,
Delivered,
Verified,
Cancelled,
}

#[derive(Clone, Queryable, Insertable, AsChangeset, Debug, PartialEq)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::migrations::*;
pub(crate) struct Migrate;

impl MigrationFragment for Migrate {
fn identifier(&self) -> &'static str {
"add_cancelled_status_to_invoice"
}

fn migrate(&self, connection: &StorageConnection) -> anyhow::Result<()> {
if cfg!(feature = "postgres") {
sql!(
connection,
r#"
ALTER TYPE invoice_status ADD VALUE IF NOT EXISTS 'CANCELLED';
"#,
)?;
}
Ok(())
}
}
2 changes: 2 additions & 0 deletions server/repository/src/migrations/v2_06_00/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod add_program_deleted_datetime;
mod add_program_id_to_invoice;
mod backend_plugins;
mod prescribed_quantity_store_pref;
mod add_cancelled_status_to_invoice;

pub(crate) struct V2_06_00;

Expand All @@ -37,6 +38,7 @@ impl Migration for V2_06_00 {
Box::new(prescribed_quantity_store_pref::Migrate),
Box::new(add_name_next_of_kin_name::Migrate),
Box::new(add_name_insurance_join::Migrate),
Box::new(add_cancelled_status_to_invoice::Migrate),
]
}
}
Expand Down
16 changes: 16 additions & 0 deletions server/repository/src/mock/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,21 @@ pub fn mock_prescription_verified() -> InvoiceRow {
})
}

pub fn mock_prescription_cancelled() -> InvoiceRow {
inline_init(|r: &mut InvoiceRow| {
r.id = String::from("prescription_cancelled");
r.name_link_id = String::from("testId");
r.store_id = String::from("store_a");
r.invoice_number = 1;
r.r#type = InvoiceType::Prescription;
r.status = InvoiceStatus::Cancelled;
r.created_datetime = NaiveDate::from_ymd_opt(1970, 1, 1)
.unwrap()
.and_hms_milli_opt(21, 30, 0, 0)
.unwrap();
})
}

pub fn mock_supplier_return_a() -> InvoiceRow {
inline_init(|r: &mut InvoiceRow| {
r.id = String::from("supplier_return_a");
Expand Down Expand Up @@ -531,6 +546,7 @@ pub fn mock_outbound_shipments() -> Vec<InvoiceRow> {
mock_prescription_a(),
mock_prescription_picked(),
mock_prescription_verified(),
mock_prescription_cancelled(),
]
}

Expand Down
2 changes: 2 additions & 0 deletions server/service/src/activity_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ pub fn log_type_from_invoice_status(status: &InvoiceStatus, prescription: bool)
from::Delivered => to::InvoiceStatusDelivered,
from::Verified if prescription => to::PrescriptionStatusVerified,
from::Verified => to::InvoiceStatusVerified,
from::Cancelled if prescription => to::PrescriptionStatusCancelled,
from::Cancelled => to::InvoiceStatusCancelled,
}
}

Expand Down
3 changes: 3 additions & 0 deletions server/service/src/dashboard/invoice_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ fn invoices_count(
InvoiceStatus::Verified => {
invoice_filter = invoice_filter.verified_datetime(datetime_filter)
}
InvoiceStatus::Cancelled => {
//TODO do we want invoice_filter = invoice_filter.cancelled_datetime(datetime_filter)
}
}
repo.count(Some(invoice_filter))
}
Expand Down
4 changes: 4 additions & 0 deletions server/service/src/sync/translations/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ fn legacy_invoice_status(t: &InvoiceType, status: &InvoiceStatus) -> Option<Lega
InvoiceStatus::Shipped => LegacyTransactStatus::Fn,
InvoiceStatus::Delivered => LegacyTransactStatus::Fn,
InvoiceStatus::Verified => LegacyTransactStatus::Fn,
InvoiceStatus::Cancelled => LegacyTransactStatus::Fn, // TODO enable cancelled status to sync with mSupply https://github.com/msupply-foundation/open-msupply/issues/6495
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these comments!

},
InvoiceType::InboundShipment | InvoiceType::CustomerReturn => match status {
InvoiceStatus::New => LegacyTransactStatus::Nw,
Expand All @@ -748,6 +749,7 @@ fn legacy_invoice_status(t: &InvoiceType, status: &InvoiceStatus) -> Option<Lega
InvoiceStatus::Shipped => LegacyTransactStatus::Nw,
InvoiceStatus::Delivered => LegacyTransactStatus::Cn,
InvoiceStatus::Verified => LegacyTransactStatus::Fn,
InvoiceStatus::Cancelled => LegacyTransactStatus::Fn, // TODO enable cancelled status to sync with mSupply https://github.com/msupply-foundation/open-msupply/issues/6495
},
InvoiceType::Prescription => match status {
InvoiceStatus::New => LegacyTransactStatus::Nw,
Expand All @@ -756,6 +758,7 @@ fn legacy_invoice_status(t: &InvoiceType, status: &InvoiceStatus) -> Option<Lega
InvoiceStatus::Shipped => LegacyTransactStatus::Fn,
InvoiceStatus::Delivered => LegacyTransactStatus::Fn,
InvoiceStatus::Verified => LegacyTransactStatus::Fn,
InvoiceStatus::Cancelled => LegacyTransactStatus::Fn, // TODO enable cancelled status to sync with mSupply https://github.com/msupply-foundation/open-msupply/issues/6495
},
InvoiceType::InventoryAddition | InvoiceType::InventoryReduction | InvoiceType::Repack => {
match status {
Expand All @@ -765,6 +768,7 @@ fn legacy_invoice_status(t: &InvoiceType, status: &InvoiceStatus) -> Option<Lega
InvoiceStatus::Shipped => LegacyTransactStatus::Nw,
InvoiceStatus::Delivered => LegacyTransactStatus::Nw,
InvoiceStatus::Verified => LegacyTransactStatus::Fn,
InvoiceStatus::Cancelled => LegacyTransactStatus::Fn, // TODO enable cancelled status to sync with mSupply https://github.com/msupply-foundation/open-msupply/issues/6495
}
}
};
Expand Down
Loading