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);