Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 5.1.0-b1
-
Component/s: None
-
Labels:None
Description
To reproduce:
- Enable vat validation
- Create a client without a vat id
- Edit the client to use a valid vat id and a different country than the one they were created with
- Revisit the edit page and see that the client is not marked as tax exempt
The reason this bug occurs is that the Clients model looks at the client's country to validate the tax_id setting, but it does so while in a transaction and thus fetches the previous country and not the newly submitted one. To fix this we'll need to resave the tax_id after the country change has been commited.
To resolve:
In Clients::setSettings() change
if ( $company_settings['enable_eu_vat'] == 'true' && $company_settings['tax_exempt_eu_vat'] == 'true' && isset($vars['tax_exempt']) && isset($vars['tax_id']) && in_array($client->country, $europe_tax->getCountries()) ) {
To
if ( $company_settings['enable_eu_vat'] == 'true' && $company_settings['tax_exempt_eu_vat'] == 'true' && isset($vars['tax_id']) && in_array($client->country, $europe_tax->getCountries()) ) {
In AdminClients::edit() change
// Success, commit $this->Clients->commit(); $this->flashMessage('message', Language::_('AdminClients.!success.client_updated', true)); $this->redirect($this->base_uri . 'clients/view/' . $client->id . '/');
To
// Success, commit $this->Clients->commit(); if (isset($settings['tax_id'])) { $this->Clients->setSettings( $client->id, ['tax_id' => $settings['tax_id']], ['tax_id', 'tax_exempt'] ); } $this->flashMessage('message', Language::_('AdminClients.!success.client_updated', true)); $this->redirect($this->base_uri . 'clients/view/' . $client->id . '/');
In ClientMain::edit() change
// Success, commit $this->Clients->commit(); $this->flashMessage('message', Language::_('ClientMain.!success.client_updated', true)); $this->redirect($this->base_uri);
To
// Success, commit $this->Clients->commit(); if (isset($new_client_settings['tax_id'])) { $this->Clients->setSettings( $this->client->id, ['tax_id' => $new_client_settings['tax_id']], ['tax_id', 'tax_exempt'] ); } $this->flashMessage('message', Language::_('ClientMain.!success.client_updated', true)); $this->redirect($this->base_uri);
In Clients::create() change
// Success, commit $this->commit(); $client = $this->get($client_id);
To
// Success, commit $this->commit(); if (isset($vars['settings']['tax_id'])) { $this->setSettings( $vars['client_id'], ['tax_id' => $vars['settings']['tax_id']], ['tax_id', 'tax_exempt'] ); } $client = $this->get($client_id);
Activity
Jonathan Reissmueller
created issue -
Jonathan Reissmueller
made changes -
Field | Original Value | New Value |
---|---|---|
Rank | Ranked higher |
Jonathan Reissmueller
made changes -
Rank | Ranked higher |
Jonathan Reissmueller
made changes -
Description |
To reproduce:
* Enable vat validation * Create a client without a vat id * Edit the client to use a valid vat id and a different country than the one they were created with * Revisit the edit page and see that the client is not marked as tax exempt The reason this bug occurs is that the Clients model looks at the client's country to validate the tax_id setting, but it does so while in a transaction and thus fetches the previous country and not the newly submitted one. To fix this we'll need to resave the tax_id after the country change has been commited. To resolve: In Clients::setSettings() change {code:java} if ( $company_settings['enable_eu_vat'] == 'true' && $company_settings['tax_exempt_eu_vat'] == 'true' && isset($vars['tax_exempt']) && isset($vars['tax_id']) && in_array($client->country, $europe_tax->getCountries()) ) { {code} To {code:java} if ( $company_settings['enable_eu_vat'] == 'true' && $company_settings['tax_exempt_eu_vat'] == 'true' && isset($vars['tax_id']) && in_array($client->country, $europe_tax->getCountries()) ) { {code} In AdminClients::edit() change {code:java} // Success, commit $this->Clients->commit(); $this->flashMessage('message', Language::_('AdminClients.!success.client_updated', true)); $this->redirect($this->base_uri . 'clients/view/' . $client->id . '/'); {code} To {code:java} // Success, commit $this->Clients->commit(); if (isset($settings['tax_id'])) { $this->Clients->setSettings( $client->id, ['tax_id' => $settings['tax_id']], ['tax_id', 'tax_exempt'] ); } $this->flashMessage('message', Language::_('AdminClients.!success.client_updated', true)); $this->redirect($this->base_uri . 'clients/view/' . $client->id . '/'); {code} In ClientMain::edit() change {code:java} // Success, commit $this->Clients->commit(); $this->flashMessage('message', Language::_('ClientMain.!success.client_updated', true)); $this->redirect($this->base_uri); {code} To {code:java} // Success, commit $this->Clients->commit(); if (isset($new_client_settings['tax_id'])) { $this->Clients->setSettings( $this->client->id, ['tax_id' => $new_client_settings['tax_id']], ['tax_id', 'tax_exempt'] ); } $this->flashMessage('message', Language::_('ClientMain.!success.client_updated', true)); $this->redirect($this->base_uri); {code} |
To reproduce:
* Enable vat validation * Create a client without a vat id * Edit the client to use a valid vat id and a different country than the one they were created with * Revisit the edit page and see that the client is not marked as tax exempt The reason this bug occurs is that the Clients model looks at the client's country to validate the tax_id setting, but it does so while in a transaction and thus fetches the previous country and not the newly submitted one. To fix this we'll need to resave the tax_id after the country change has been commited. To resolve: In Clients::setSettings() change {code:java} if ( $company_settings['enable_eu_vat'] == 'true' && $company_settings['tax_exempt_eu_vat'] == 'true' && isset($vars['tax_exempt']) && isset($vars['tax_id']) && in_array($client->country, $europe_tax->getCountries()) ) { {code} To {code:java} if ( $company_settings['enable_eu_vat'] == 'true' && $company_settings['tax_exempt_eu_vat'] == 'true' && isset($vars['tax_id']) && in_array($client->country, $europe_tax->getCountries()) ) { {code} In AdminClients::edit() change {code:java} // Success, commit $this->Clients->commit(); $this->flashMessage('message', Language::_('AdminClients.!success.client_updated', true)); $this->redirect($this->base_uri . 'clients/view/' . $client->id . '/'); {code} To {code:java} // Success, commit $this->Clients->commit(); if (isset($settings['tax_id'])) { $this->Clients->setSettings( $client->id, ['tax_id' => $settings['tax_id']], ['tax_id', 'tax_exempt'] ); } $this->flashMessage('message', Language::_('AdminClients.!success.client_updated', true)); $this->redirect($this->base_uri . 'clients/view/' . $client->id . '/'); {code} In ClientMain::edit() change {code:java} // Success, commit $this->Clients->commit(); $this->flashMessage('message', Language::_('ClientMain.!success.client_updated', true)); $this->redirect($this->base_uri); {code} To {code:java} // Success, commit $this->Clients->commit(); if (isset($new_client_settings['tax_id'])) { $this->Clients->setSettings( $this->client->id, ['tax_id' => $new_client_settings['tax_id']], ['tax_id', 'tax_exempt'] ); } $this->flashMessage('message', Language::_('ClientMain.!success.client_updated', true)); $this->redirect($this->base_uri); {code} In Clients::create() change {code:java} // Success, commit $this->commit(); $client = $this->get($client_id); {code} To {code:java} // Success, commit $this->commit(); if (isset($vars['settings']['tax_id'])) { $this->setSettings( $vars['client_id'], ['tax_id' => $vars['settings']['tax_id']], ['tax_id', 'tax_exempt'] ); } $client = $this->get($client_id); {code} |
Jonathan Reissmueller
made changes -
Sprint | 5.1.0 Sprint 5 [ 132 ] |
Jonathan Reissmueller
made changes -
Rank | Ranked higher |
Jonathan Reissmueller
made changes -
Status | Open [ 1 ] | In Progress [ 3 ] |
Jonathan Reissmueller
made changes -
Status | In Progress [ 3 ] | In Review [ 5 ] |
Resolution | Fixed [ 1 ] |
Jonathan Reissmueller
made changes -
Remaining Estimate | 0 minutes [ 0 ] | |
Time Spent | 16 minutes [ 960 ] | |
Worklog Id | 14902 [ 14902 ] |
Jonathan Reissmueller
made changes -
Status | In Review [ 5 ] | Closed [ 6 ] |