Skip to content

Commit

Permalink
fix per consegne veloci. closes #290
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Oct 6, 2024
1 parent 04d9792 commit 4d490b4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
14 changes: 13 additions & 1 deletion code/app/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,19 @@ public function getDeliveredTaxedAttribute()
public function getProductsWithFriendsAttribute()
{
return $this->innerCache('friends_products', function($obj) {
$products = $this->products;
/*
Qui devo fare una copia di $this->products anziché usarlo
direttamente, altrimenti finisco con l'alterare l'elenco stesso
dei prodotti relazionati alla prenotazione aggiungendoci anche
quelli degli amici con effetti poco graditi (e.g. in fase di
gestione della consegna, altero l'entità del prodotto dell'amico
anziché quello della prenotazione primaria)
*/
$products = new Collection();
foreach($this->products as $p) {
$products->push($p);
}

$friends = $this->friends_bookings;

foreach($friends as $sub) {
Expand Down
52 changes: 51 additions & 1 deletion code/tests/Services/FastBookingsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function setUp(): void
parent::setUp();

$this->sample_order = $this->initOrder(null);
$this->userWithBasePerms = $this->createRoleAndUser($this->gas, 'supplier.book');
$this->userWithBasePerms = $this->createRoleAndUser($this->gas, 'supplier.book,users.subusers');
}

/*
Expand Down Expand Up @@ -88,6 +88,56 @@ public function testFastShippingFiltered()
}
}

/*
Consegne veloci con amici
*/
public function testFastShippingWithFriend()
{
$friend = $this->createFriend($this->userWithBasePerms);
$this->actingAs($friend);

\Log::debug('qui: ' . $friend->id);

list($data_friend, $booked_count_friend, $total_friend) = $this->randomQuantities($this->sample_order->products);
$data_friend['action'] = 'booked';
app()->make('BookingsService')->bookingUpdate($data_friend, $this->sample_order->aggregate, $friend, false);

$this->nextRound();

$this->actingAs($this->userWithShippingPerms);
$order = app()->make('OrdersService')->show($this->sample_order->id);
app()->make('FastBookingsService')->fastShipping($this->userWithShippingPerms, $order->aggregate, null);

$this->nextRound();
$order = app()->make('OrdersService')->show($this->sample_order->id);
$this->assertEquals(2, $order->bookings->count());
$this->assertEquals(1, count($order->topLevelBookings()));

foreach($order->bookings as $booking) {
$this->assertEquals($booking->status, 'shipped');

foreach($booking->products as $product) {
if ($booking->user->isFriend()) {
$this->assertEquals(0, $product->delivered);
}
else {
$this->assertEquals(0, $product->quantity);
$this->assertEquals($data_friend[$product->product_id], $product->delivered);
}
}

if ($booking->user->isFriend()) {
$this->assertNull($booking->payment);
}
else {
$this->assertEquals($booking->payment->amount, $booking->getValue('effective', true));
}
}

$summary = $order->aggregate->reduxData();
$this->assertTrue($summary->price_delivered > 0);
}

/*
Consegne veloci su prenotazioni salvate
*/
Expand Down

0 comments on commit 4d490b4

Please sign in to comment.