mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 05:24:29 -04:00
Import Company Test
This commit is contained in:
parent
442e416840
commit
8c643edf8f
@ -144,14 +144,15 @@ class CompanyExport implements ShouldQueue
|
||||
})->all();
|
||||
|
||||
|
||||
$this->export_data['clients'] = $this->company->clients->map(function ($client){
|
||||
$this->export_data['clients'] = $this->company->clients->makeVisible(['id','private_notes','user_id','company_id','last_login'])->map(function ($client){
|
||||
|
||||
$client = $this->transformArrayOfKeys($client, ['id', 'company_id', 'user_id',' assigned_user_id', 'group_settings_id']);
|
||||
$client = $this->transformArrayOfKeys($client, ['company_id', 'user_id', 'assigned_user_id', 'group_settings_id']);
|
||||
|
||||
return $client;
|
||||
return $client->makeVisible(['id','private_notes','user_id','company_id','last_login']);
|
||||
|
||||
})->all();
|
||||
|
||||
|
||||
$this->export_data['company'] = $this->company->toArray();
|
||||
|
||||
$this->export_data['company_gateways'] = $this->company->company_gateways->map(function ($company_gateway){
|
||||
|
@ -65,6 +65,8 @@ class CompanyImport implements ShouldQueue
|
||||
'users',
|
||||
// 'payment_terms',
|
||||
// 'tax_rates',
|
||||
// 'expense_categories',
|
||||
// 'task_statuses',
|
||||
// 'clients',
|
||||
// 'company_gateways',
|
||||
// 'client_gateway_tokens',
|
||||
@ -76,11 +78,15 @@ class CompanyImport implements ShouldQueue
|
||||
// 'recurring_invoices',
|
||||
// 'quotes',
|
||||
// 'payments',
|
||||
// 'expense_categories',
|
||||
// 'task_statuses',
|
||||
// 'expenses',
|
||||
// 'tasks',
|
||||
// 'documents',
|
||||
// 'subscriptions',
|
||||
// 'webhooks',
|
||||
// 'system_logs',
|
||||
// 'paymentables',
|
||||
// 'company_ledger',
|
||||
// 'backups',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -22,6 +22,7 @@ use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentTerm;
|
||||
use App\Models\Product;
|
||||
use App\Models\TaskStatus;
|
||||
use App\Models\TaxRate;
|
||||
use App\Models\User;
|
||||
use App\Models\Vendor;
|
||||
@ -274,7 +275,7 @@ class ImportCompanyTest extends TestCase
|
||||
/***************************** Expense Category *****************************/
|
||||
ExpenseCategory::unguard();
|
||||
|
||||
$this->assertEquals(2, count($this->backup_json_object->tax_rates));
|
||||
$this->assertEquals(2, count($this->backup_json_object->expense_categories));
|
||||
|
||||
foreach($this->backup_json_object->expense_categories as $obj)
|
||||
{
|
||||
@ -303,6 +304,79 @@ class ImportCompanyTest extends TestCase
|
||||
$this->assertEquals(2, ExpenseCategory::count());
|
||||
/***************************** Expense Category *****************************/
|
||||
|
||||
|
||||
/***************************** Task Statuses *****************************/
|
||||
TaskStatus::unguard();
|
||||
|
||||
$this->assertEquals(4, count($this->backup_json_object->task_statuses));
|
||||
|
||||
foreach($this->backup_json_object->task_statuses as $obj)
|
||||
{
|
||||
|
||||
$user_id = $this->transformId('users', $obj->user_id);
|
||||
|
||||
$obj_array = (array)$obj;
|
||||
unset($obj_array['user_id']);
|
||||
unset($obj_array['company_id']);
|
||||
unset($obj_array['account_id']);
|
||||
unset($obj_array['hashed_id']);
|
||||
unset($obj_array['id']);
|
||||
unset($obj_array['tax_rate_id']);
|
||||
|
||||
$new_obj = TaskStatus::firstOrNew(
|
||||
['name' => $obj->name, 'company_id' => $this->company->id],
|
||||
$obj_array,
|
||||
);
|
||||
|
||||
$new_obj->save(['timestamps' => false]);
|
||||
|
||||
}
|
||||
|
||||
TaskStatus::reguard();
|
||||
|
||||
$this->assertEquals(4, TaskStatus::count());
|
||||
/***************************** Task Statuses *****************************/
|
||||
|
||||
/***************************** Clients *****************************/
|
||||
Client::unguard();
|
||||
|
||||
$this->assertEquals(1, count($this->backup_json_object->clients));
|
||||
|
||||
foreach($this->backup_json_object->clients as $obj)
|
||||
{
|
||||
|
||||
$user_id = $this->transformId('users', $obj->user_id);
|
||||
|
||||
$obj_array = (array)$obj;
|
||||
unset($obj_array['user_id']);
|
||||
unset($obj_array['company_id']);
|
||||
unset($obj_array['account_id']);
|
||||
unset($obj_array['hashed_id']);
|
||||
unset($obj_array['id']);
|
||||
unset($obj_array['gateway_tokens']);
|
||||
unset($obj_array['contacts']);
|
||||
unset($obj_array['documents']);
|
||||
|
||||
// $obj_array['settings'] = json_encode($obj_array['settings']);
|
||||
// nlog($obj_array);
|
||||
|
||||
$new_obj = Client::firstOrNew(
|
||||
['number' => $obj->number, 'company_id' => $this->company->id],
|
||||
$obj_array,
|
||||
);
|
||||
|
||||
$new_obj->save(['timestamps' => false]);
|
||||
|
||||
$this->ids['clients']["{$obj->hashed_id}"] = $new_obj->id;
|
||||
|
||||
}
|
||||
|
||||
Client::reguard();
|
||||
|
||||
$this->assertEquals(1, Client::count());
|
||||
/***************************** Clients *****************************/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user