Pretty order numbers
This commit is contained in:
1 parent
ab0c51819c
commit
341e9423ce
6 files changed
+56
-3
No files matched your search
@@ -374,7 +374,7 @@ class BrightpearlService extends BaseService {
|
|||||||
currency: {
|
currency: {
|
||||||
code: fromOrder.currency_code,
|
code: fromOrder.currency_code,
|
||||||
},
|
},
|
||||||
ref: fromOrder._id,
|
ref: fromOrder.display_id,
|
||||||
externalRef: fromOrder._id,
|
externalRef: fromOrder._id,
|
||||||
channelId: this.options.channel_id || `1`,
|
channelId: this.options.channel_id || `1`,
|
||||||
installedIntegrationInstanceId: authData.installation_instance_id,
|
installedIntegrationInstanceId: authData.installation_instance_id,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export default async ({ container }) => {
|
export default async ({ container }) => {
|
||||||
|
const counterService = container.resolve("counterService")
|
||||||
const storeService = container.resolve("storeService")
|
const storeService = container.resolve("storeService")
|
||||||
const profileService = container.resolve("shippingProfileService")
|
const profileService = container.resolve("shippingProfileService")
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ export default async ({ container }) => {
|
|||||||
payment_providers: payIds,
|
payment_providers: payIds,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await counterService.createDefaults()
|
||||||
await profileService.createDefault()
|
await profileService.createDefault()
|
||||||
await profileService.createGiftCardDefault()
|
await profileService.createGiftCardDefault()
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import mongoose from "mongoose"
|
||||||
|
import { BaseModel } from "medusa-interfaces"
|
||||||
|
|
||||||
|
class CounterModel extends BaseModel {
|
||||||
|
static modelName = "Counter"
|
||||||
|
|
||||||
|
static schema = {
|
||||||
|
_id: String,
|
||||||
|
next: Number,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CounterModel
|
||||||
@@ -15,6 +15,7 @@ class OrderModel extends BaseModel {
|
|||||||
static modelName = "Order"
|
static modelName = "Order"
|
||||||
|
|
||||||
static schema = {
|
static schema = {
|
||||||
|
display_id: { type: String, required: true, unique: true },
|
||||||
// pending, completed, archived, cancelled
|
// pending, completed, archived, cancelled
|
||||||
status: { type: String, default: "pending" },
|
status: { type: String, default: "pending" },
|
||||||
// not_fulfilled, partially_fulfilled (some line items have been returned), fulfilled, returned,
|
// not_fulfilled, partially_fulfilled (some line items have been returned), fulfilled, returned,
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import _ from "lodash"
|
||||||
|
import { Validator, MedusaError } from "medusa-core-utils"
|
||||||
|
import { BaseService } from "medusa-interfaces"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides layer to manipulate carts.
|
||||||
|
* @implements BaseService
|
||||||
|
*/
|
||||||
|
class CounterService extends BaseService {
|
||||||
|
constructor({ counterModel }) {
|
||||||
|
super()
|
||||||
|
|
||||||
|
/** @private @const {CartModel} */
|
||||||
|
this.counterModel_ = counterModel
|
||||||
|
}
|
||||||
|
|
||||||
|
async createDefaults() {
|
||||||
|
const orderCounter = await this.counterModel_.findOne({ _id: "orders" })
|
||||||
|
if (!orderCounter) {
|
||||||
|
await this.counterModel_.create({ _id: "orders", next: 1000 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getNext(id) {
|
||||||
|
const counter = await this.counterModel_.updateOne(
|
||||||
|
{ _id: id },
|
||||||
|
{ $inc: { next: 1 } }
|
||||||
|
)
|
||||||
|
return counter.next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CounterService
|
||||||
@@ -17,6 +17,7 @@ class OrderService extends BaseService {
|
|||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
orderModel,
|
orderModel,
|
||||||
|
counterService,
|
||||||
paymentProviderService,
|
paymentProviderService,
|
||||||
shippingProfileService,
|
shippingProfileService,
|
||||||
discountService,
|
discountService,
|
||||||
@@ -54,6 +55,8 @@ class OrderService extends BaseService {
|
|||||||
|
|
||||||
/** @private @const {EventBus} */
|
/** @private @const {EventBus} */
|
||||||
this.eventBus_ = eventBusService
|
this.eventBus_ = eventBusService
|
||||||
|
|
||||||
|
this.counterService_ = counterService
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -343,6 +346,7 @@ class OrderService extends BaseService {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const o = {
|
const o = {
|
||||||
|
display_id: await this.counterService_.getNext("orders"),
|
||||||
payment_method: {
|
payment_method: {
|
||||||
provider_id: paymentSession.provider_id,
|
provider_id: paymentSession.provider_id,
|
||||||
data: paymentData,
|
data: paymentData,
|
||||||
@@ -789,8 +793,8 @@ class OrderService extends BaseService {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...i,
|
...i,
|
||||||
returned_quantity: returnedQuantity
|
returned_quantity: returnedQuantity,
|
||||||
returned
|
returned,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!i.returned) {
|
if (!i.returned) {
|
||||||
|
|||||||
Reference in new issue
Block a user