fixed tax_ids check
This commit is contained in:
@ -26,27 +26,27 @@ class CreateItemTaxes extends Job
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Item
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
\DB::transaction(function () {
|
||||
// This controller for BC < 2.1
|
||||
// BC for 2.0 version
|
||||
if (!empty($this->request['tax_id'])) {
|
||||
ItemTax::create([
|
||||
'company_id' => $this->item->company_id,
|
||||
'item_id' => $this->item->id,
|
||||
'tax_id' => $this->request['tax_id']
|
||||
]);
|
||||
} else {
|
||||
$this->request['tax_ids'][] = $this->request['tax_id'];
|
||||
}
|
||||
|
||||
if (empty($this->request['tax_ids'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
\DB::transaction(function () {
|
||||
foreach ($this->request['tax_ids'] as $tax_id) {
|
||||
ItemTax::create([
|
||||
'company_id' => $this->item->company_id,
|
||||
'item_id' => $this->item->id,
|
||||
'tax_id' => $tax_id
|
||||
'tax_id' => $tax_id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return $this->item->taxes;
|
||||
|
@ -28,7 +28,6 @@ class Item extends Factory
|
||||
'purchase_price' => $this->faker->randomFloat(2, 10, 20),
|
||||
'sale_price' => $this->faker->randomFloat(2, 10, 20),
|
||||
'category_id' => $this->company->categories()->item()->get()->random(1)->pluck('id')->first(),
|
||||
'tax_ids' => [],
|
||||
'enabled' => $this->faker->boolean ? 1 : 0,
|
||||
];
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class ItemsTest extends FeatureTestCase
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
|
||||
$this->assertDatabaseHas('items', $this->getAssertRequest($request));
|
||||
$this->assertDatabaseHas('items', $request);
|
||||
}
|
||||
|
||||
public function testItShouldSeeItemUpdatePage()
|
||||
@ -64,7 +64,7 @@ class ItemsTest extends FeatureTestCase
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
|
||||
$this->assertDatabaseHas('items', $this->getAssertRequest($request));
|
||||
$this->assertDatabaseHas('items', $request);
|
||||
}
|
||||
|
||||
public function testItShouldDeleteItem()
|
||||
@ -79,18 +79,11 @@ class ItemsTest extends FeatureTestCase
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
|
||||
$this->assertSoftDeleted('items', $this->getAssertRequest($request));
|
||||
$this->assertSoftDeleted('items', $request);
|
||||
}
|
||||
|
||||
public function getRequest()
|
||||
{
|
||||
return Item::factory()->enabled()->raw();
|
||||
}
|
||||
|
||||
public function getAssertRequest($request)
|
||||
{
|
||||
unset($request['tax_ids']);
|
||||
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user