set up unfonctionnal rework, TODO -> pricing separation
This commit is contained in:
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||
"cloud.o-forge.io/core/oc-lib/models/buying_status"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/purchase_resource"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
@@ -172,7 +172,7 @@ func (o *Order) draftBookOrder(scheduler *workflow_execution.WorkflowSchedule, r
|
||||
return draftedBookings, errors.New("no request found")
|
||||
}
|
||||
for _, exec := range scheduler.WorkflowExecutions {
|
||||
bookings := exec.ToBookings(scheduler.Workflow)
|
||||
bookings := exec.Book(scheduler.Workflow)
|
||||
for _, booking := range bookings {
|
||||
_, err := (&peer.Peer{}).LaunchPeerExecution(booking.DestPeerID, "",
|
||||
tools.BOOKING, tools.POST, booking.Serialize(booking), request.Caller)
|
||||
@@ -261,15 +261,14 @@ func (d *PeerOrder) Pay(request *tools.APIRequest, response chan *PeerOrder, wg
|
||||
d.Status = PAID // TO REMOVE LATER IT'S A MOCK
|
||||
if d.Status == PAID {
|
||||
for _, b := range d.Items {
|
||||
if !b.Item.IsBuying(request) {
|
||||
if !b.Item.IsPurchased(request) {
|
||||
continue
|
||||
}
|
||||
accessor := buying_status.NewAccessor(request)
|
||||
accessor.StoreOne(&buying_status.BuyingStatus{
|
||||
BuyingDate: time.Now(),
|
||||
ResourceID: b.Item.GetID(),
|
||||
ResourceType: b.Item.GetType(),
|
||||
EndBuyingDate: b.Item.GetLocationEnd(),
|
||||
accessor := purchase_resource.NewAccessor(request)
|
||||
accessor.StoreOne(&purchase_resource.PurchaseResource{
|
||||
ResourceID: b.Item.GetID(),
|
||||
ResourceType: b.Item.GetType(),
|
||||
EndDate: b.Item.GetLocationEnd(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -304,21 +303,21 @@ func (d *PeerOrder) SetName() {
|
||||
}
|
||||
|
||||
type PeerItemOrder struct {
|
||||
Quantity int `json:"quantity,omitempty" bson:"quantity,omitempty"`
|
||||
BuyingStatus buying_status.BuyingStatus `json:"buying_status,omitempty" bson:"buying_status,omitempty"`
|
||||
Item pricing.PricedItemITF `json:"item,omitempty" bson:"item,omitempty"`
|
||||
Quantity int `json:"quantity,omitempty" bson:"quantity,omitempty"`
|
||||
Purchase purchase_resource.PurchaseResource `json:"purchase,omitempty" bson:"purchase,omitempty"`
|
||||
Item pricing.PricedItemITF `json:"item,omitempty" bson:"item,omitempty"`
|
||||
}
|
||||
|
||||
func (d *PeerItemOrder) GetPrice(request *tools.APIRequest) (float64, error) {
|
||||
accessor := buying_status.NewAccessor(request)
|
||||
accessor := purchase_resource.NewAccessor(request)
|
||||
search, code, _ := accessor.Search(&dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"resource_id": {{Operator: dbs.EQUAL.String(), Value: d.Item.GetID()}},
|
||||
},
|
||||
}, "", d.BuyingStatus.IsDraft)
|
||||
}, "", d.Purchase.IsDraft)
|
||||
if code == 200 && len(search) > 0 {
|
||||
for _, s := range search {
|
||||
if s.(*buying_status.BuyingStatus).EndBuyingDate == nil || time.Now().UTC().After(*s.(*buying_status.BuyingStatus).EndBuyingDate) {
|
||||
if s.(*purchase_resource.PurchaseResource).EndDate == nil || time.Now().UTC().After(*s.(*purchase_resource.PurchaseResource).EndDate) {
|
||||
return 0, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user