diff --git a/account_asset_management/models/account_asset.py b/account_asset_management/models/account_asset.py index 7dd2b08a7..ed280dfcd 100644 --- a/account_asset_management/models/account_asset.py +++ b/account_asset_management/models/account_asset.py @@ -306,6 +306,16 @@ class AccountAsset(models.Model): if self.method_time != 'year': self.prorata = True + @api.onchange('method_number') + def _onchange_method_number(self): + if self.method_number and self.method_end: + self.method_end = False + + @api.onchange('method_end') + def _onchange_method_end(self): + if self.method_end and self.method_number: + self.method_number = 0 + @api.model def create(self, vals): if vals.get('method_time') != 'year' and not vals.get('prorata'): @@ -665,7 +675,7 @@ class AccountAsset(models.Model): return depreciation_start_date def _get_depreciation_stop_date(self, depreciation_start_date): - if self.method_time == 'year': + if self.method_time == 'year' and not self.method_end: depreciation_stop_date = depreciation_start_date + \ relativedelta(years=self.method_number, days=-1) elif self.method_time == 'number': @@ -683,7 +693,7 @@ class AccountAsset(models.Model): elif self.method_period == 'year': depreciation_stop_date = depreciation_start_date + \ relativedelta(years=self.method_number, days=-1) - elif self.method_time == 'end': + elif self.method_time == 'year' and self.method_end: depreciation_stop_date = self.method_end return depreciation_stop_date @@ -706,7 +716,7 @@ class AccountAsset(models.Model): Override this method if you want to compute differently the yearly amount. """ - if not self.use_leap_years: + if not self.use_leap_years and self.method_number: return self.depreciation_base / self.method_number year = entry['date_stop'].year cy_days = calendar.isleap(year) and 366 or 365 @@ -954,7 +964,8 @@ class AccountAsset(models.Model): def _compute_depreciation_table(self): table = [] - if self.method_time in ['year', 'number'] and not self.method_number: + if self.method_time in ['year', 'number'] \ + and not self.method_number and not self.method_end: return table company = self.company_id asset_date_start = self.date_start diff --git a/account_asset_management/models/account_asset_profile.py b/account_asset_management/models/account_asset_profile.py index e850d6b1b..cd3b1f659 100644 --- a/account_asset_management/models/account_asset_profile.py +++ b/account_asset_management/models/account_asset_profile.py @@ -153,7 +153,7 @@ class AccountAssetProfile(models.Model): 'Number' and 'End' Time Methods. """ return [ - ('year', _('Number of Years')), + ('year', _('Number of Years or end date')), ] @api.multi diff --git a/account_asset_management/views/account_asset.xml b/account_asset_management/views/account_asset.xml index 3bfc32599..182470eb2 100644 --- a/account_asset_management/views/account_asset.xml +++ b/account_asset_management/views/account_asset.xml @@ -65,7 +65,7 @@ attrs="{'invisible': [('method_time', 'not in', ['number', 'year'])], 'required': [('method_time', 'in', ['number', 'year'])]}"/> + attrs="{'required': [('method_time', '=', 'end')], 'invisible': [('method_time', 'in', ['number'])]}"/>