mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[ADD] allows setting a depreciation ending date
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
attrs="{'invisible': [('method_time', 'not in', ['number', 'year'])], 'required': [('method_time', 'in', ['number', 'year'])]}"/>
|
||||
<field name="method_period"/>
|
||||
<field name="method_end"
|
||||
attrs="{'required': [('method_time', '=', 'end')], 'invisible': [('method_time', 'in', ['number', 'year'])]}"/>
|
||||
attrs="{'required': [('method_time', '=', 'end')], 'invisible': [('method_time', 'in', ['number'])]}"/>
|
||||
<field name="days_calc"/>
|
||||
<field name="use_leap_years"
|
||||
attrs="{'invisible': [('days_calc', '=', True)]}"/>
|
||||
|
||||
Reference in New Issue
Block a user