Skip to content

Commit

Permalink
Merge pull request #1 from Eficent/12.0-imp-account_asset_management
Browse files Browse the repository at this point in the history
[12.0[IMP][account_asset_management] allows setting a depreciation ending date
  • Loading branch information
Saran440 committed Oct 25, 2019
2 parents b7b3edb + ad1dbf4 commit 75432b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 deletions account_asset_management/models/account_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ def _onchange_method_time(self):
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'):
Expand Down Expand Up @@ -665,7 +675,7 @@ def _get_depreciation_start_date(self, fy):
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':
Expand All @@ -683,7 +693,7 @@ def _get_depreciation_stop_date(self, depreciation_start_date):
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

Expand All @@ -706,7 +716,7 @@ def _get_amount_linear(
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
Expand Down Expand Up @@ -954,7 +964,8 @@ def _get_fy_info(self, date):

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
Expand Down
2 changes: 1 addition & 1 deletion account_asset_management/models/account_asset_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _selection_method_time(self):
'Number' and 'End' Time Methods.
"""
return [
('year', _('Number of Years')),
('year', _('Number of Years or end date')),
]

@api.multi
Expand Down
2 changes: 1 addition & 1 deletion account_asset_management/views/account_asset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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)]}"/>
Expand Down

0 comments on commit 75432b5

Please sign in to comment.