2
0

[MIG] account_asset_management: Migration to 12.0

This commit is contained in:
Henrik Norlin 2019-01-11 15:24:15 +01:00 committed by Rodrigo
parent 0cece3a4b7
commit 886abfe610
9 changed files with 52 additions and 63 deletions

View File

@ -3,7 +3,7 @@
{
'name': 'Assets Management',
'version': '11.0.1.0.0',
'version': '12.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'account_fiscal_year',

View File

@ -5,5 +5,5 @@ from . import account_asset_line
from . import account_asset_recompute_trigger
from . import account_invoice
from . import account_move
from . import date_range
#from . import date_range
from . import res_config_settings

View File

@ -86,8 +86,7 @@ class AccountAsset(models.Model):
ondelete='restrict',
index=True,
)
parent_left = fields.Integer(index=True)
parent_right = fields.Integer(index=True)
parent_path = fields.Char(index=True)
child_ids = fields.One2many(
comodel_name='account.asset',
inverse_name='parent_id',
@ -510,8 +509,7 @@ class AccountAsset(models.Model):
continue
# group lines prior to depreciation start period
depreciation_start_date = fields.Datetime.from_string(
asset.date_start)
depreciation_start_date = asset.date_start
lines = table[0]['lines']
lines1 = []
lines2 = []
@ -532,8 +530,7 @@ class AccountAsset(models.Model):
# recompute in case of deviation
depreciated_value_posted = depreciated_value = 0.0
if posted_lines:
last_depreciation_date = fields.Datetime.from_string(
last_line.line_date)
last_depreciation_date = last_line.line_date
last_date_in_table = table[-1]['lines'][-1]['date']
if last_date_in_table <= last_depreciation_date:
raise UserError(
@ -604,7 +601,7 @@ class AccountAsset(models.Model):
'amount': amount,
'asset_id': asset.id,
'name': name,
'line_date': line['date'].strftime('%Y-%m-%d'),
'line_date': line['date'],
'init_entry': entry['init'],
}
depreciated_value += amount
@ -624,9 +621,9 @@ class AccountAsset(models.Model):
a started month is counted as a full month
- years: duration in calendar years, considering also leap years
"""
fy = self.env['date.range'].browse(fy_id)
fy_date_start = fields.Datetime.from_string(fy.date_start)
fy_date_stop = fields.Datetime.from_string(fy.date_end)
fy = self.env['account.fiscal.year'].browse(fy_id)
fy_date_start = fy.date_from
fy_date_stop = fy.date_to
days = (fy_date_stop - fy_date_start).days + 1
months = (fy_date_stop.year - fy_date_start.year) * 12 \
+ (fy_date_stop.month - fy_date_start.month) + 1
@ -664,8 +661,7 @@ class AccountAsset(models.Model):
fy_id = entry['fy_id']
if self.prorata:
if firstyear:
depreciation_date_start = fields.Datetime.from_string(
self.date_start)
depreciation_date_start = self.date_start
fy_date_stop = entry['date_stop']
first_fy_asset_days = \
(fy_date_stop - depreciation_date_start).days + 1
@ -698,12 +694,9 @@ class AccountAsset(models.Model):
if the fiscal year starts in the middle of a month.
"""
if self.prorata:
depreciation_start_date = fields.Datetime.from_string(
self.date_start)
depreciation_start_date = self.date_start
else:
fy_date_start = fields.Datetime.from_string(fy.date_start)
depreciation_start_date = datetime(
fy_date_start.year, fy_date_start.month, 1)
depreciation_start_date = fy.date_from
return depreciation_start_date
def _get_depreciation_stop_date(self, depreciation_start_date):
@ -726,8 +719,7 @@ class AccountAsset(models.Model):
depreciation_stop_date = depreciation_start_date + \
relativedelta(years=self.method_number, days=-1)
elif self.method_time == 'end':
depreciation_stop_date = fields.Datetime.from_string(
self.method_end)
depreciation_stop_date = self.method_end
return depreciation_stop_date
def _get_first_period_amount(self, table, entry, depreciation_start_date,
@ -908,30 +900,31 @@ class AccountAsset(models.Model):
company = self.company_id
init_flag = False
asset_date_start = datetime.strptime(self.date_start, '%Y-%m-%d')
fy = company.find_daterange_fy(asset_date_start)
asset_date_start = self.date_start
fy = self.env['account.fiscal.year'].search([
('date_from', '<=', asset_date_start),
('date_to', '>=', asset_date_start),
('company_id', '=', company.id)])
fiscalyear_lock_date = company.fiscalyear_lock_date
if fiscalyear_lock_date and fiscalyear_lock_date >= self.date_start:
init_flag = True
if fy:
fy_id = fy.id
fy_date_start = datetime.strptime(fy.date_start, '%Y-%m-%d')
fy_date_stop = datetime.strptime(fy.date_end, '%Y-%m-%d')
fy_date_start = fy.date_from
fy_date_stop = fy.date_to
else:
# The following logic is used when no fiscal year
# is defined for the asset start date:
# - We lookup the first fiscal year defined in the system
# - The 'undefined' fiscal years are assumed to be years
# with a duration equal to a calendar year
first_fy = self.env['date.range'].search(
[('company_id', '=', self.company_id.id),
('type_id.fiscal_year', '=', True)],
order='date_end ASC', limit=1)
first_fy = self.env['account.fiscal.year'].search(
[('company_id', '=', self.company_id.id)],
order='date_to ASC', limit=1)
if not first_fy:
raise UserError(
_("No Fiscal Year defined."))
first_fy_date_start = datetime.strptime(
first_fy.date_start, '%Y-%m-%d')
first_fy_date_start = first_fy.date_from
fy_date_start = first_fy_date_start
if asset_date_start > fy_date_start:
asset_ref = self.code and '%s (ref: %s)' \
@ -946,8 +939,8 @@ class AccountAsset(models.Model):
fy_date_stop = fy_date_start + relativedelta(years=1, days=-1)
fy_id = False
fy = DummyFy(
date_start=fy_date_start.strftime('%Y-%m-%d'),
date_end=fy_date_stop.strftime('%Y-%m-%d'),
date_start=fy_date_start,
date_end=fy_date_stop,
id=False,
state='done',
dummy=True)
@ -964,21 +957,24 @@ class AccountAsset(models.Model):
'date_stop': fy_date_stop,
'init': init_flag})
fy_date_start = fy_date_stop + relativedelta(days=1)
fy = company.find_daterange_fy(fy_date_start)
fy = self.env['account.fiscal.year'].search([
('date_from', '<=', fy_date_start),
('date_to', '>=', fy_date_start),
('company_id', '=', company.id)])
if fy:
if (
fiscalyear_lock_date and
fiscalyear_lock_date >= fy.date_end
fiscalyear_lock_date >= fy.date_to
):
init_flag = True
else:
init_flag = False
fy_date_stop = datetime.strptime(fy.date_end, '%Y-%m-%d')
fy_date_stop = fy.date_to
else:
fy_date_stop = fy_date_stop + relativedelta(years=1)
if (
fiscalyear_lock_date and
fiscalyear_lock_date >= fy_date_stop.strftime('%Y-%m-%d')
fiscalyear_lock_date >= fy_date_stop
):
init_flag = True
else:

View File

@ -1,8 +1,6 @@
# Copyright 2009-2018 Noviat
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import datetime
from odoo import api, fields, models, _
import odoo.addons.decimal_precision as dp
from odoo.exceptions import UserError
@ -103,10 +101,6 @@ class AccountAssetLine(models.Model):
@api.multi
def write(self, vals):
for dl in self:
if vals.get('line_date'):
if isinstance(vals['line_date'], datetime.date):
vals['line_date'] = fields.Date.to_string(
vals['line_date'])
line_date = vals.get('line_date') or dl.line_date
asset_lines = dl.asset_id.depreciation_line_ids
if list(vals.keys()) == ['move_id'] and not vals['move_id']:
@ -145,8 +139,9 @@ class AccountAssetLine(models.Model):
"after already posted entries."))
else:
check = asset_lines.filtered(
lambda l: (l.init_entry or l.move_check) and
l.line_date > vals['line_date'] and l != dl)
lambda l: l != dl and
(l.init_entry or l.move_check) and
l.line_date > fields.Date.to_date(vals['line_date']))
if check:
raise UserError(_(
"You cannot set the date on a depreciation line "

View File

@ -5,3 +5,4 @@
- Stéphane Bidoul (Acsone)
- Adrien Peiffer (Acsone)
- Akim Juillerat <akim.juillerat@camptocamp.com>
- Henrik Norlin (Apps2GROW)

View File

@ -0,0 +1,5 @@
12.0.1.0.0 (2019-01-13)
~~~~~~~~~~~~~~~~~~~~~~~
* [BREAKING] account.asset: parent_path has replaced parent_left & parent_right (TODO: migration script)
* [BREAKING] account.asset.recompute.trigger: depends on date_range.py (TODO: re-implement in account_fiscal_year.py)

View File

@ -2,19 +2,17 @@
<odoo>
<data noupdate="1">
<record id="date_range_fy" model="date.range">
<field name="type_id" ref="account_fiscal_year.fiscalyear" />
<record id="account_fiscal_year_current" model="account.fiscal.year">
<field name="name">FY_assets</field>
<field name="date_start" eval="time.strftime('%Y-01-01')"/>
<field name="date_end" eval="time.strftime('%Y-12-31')"/>
<field name="date_from" eval="time.strftime('%Y-01-01')"/>
<field name="date_to" eval="time.strftime('%Y-12-31')"/>
<field name="company_id" ref="base.main_company"/>
</record>
<record id="date_range_fy_previous" model="date.range">
<field name="type_id" ref="account_fiscal_year.fiscalyear" />
<record id="account_fiscal_year_previous" model="account.fiscal.year">
<field name="name">FY_assets previous</field>
<field name="date_start" eval="(datetime.now() - relativedelta(years=1, month=1, day=1)).strftime('%Y-%m-%d')"/>
<field name="date_end" eval="(datetime.now() - relativedelta(years=1, month=12, day=31)).strftime('%Y-%m-%d')"/>
<field name="date_from" eval="(datetime.now() - relativedelta(years=1, month=1, day=1)).strftime('%Y-%m-%d')"/>
<field name="date_to" eval="(datetime.now() - relativedelta(years=1, month=12, day=31)).strftime('%Y-%m-%d')"/>
<field name="company_id" ref="base.main_company"/>
</record>

View File

@ -205,8 +205,8 @@
<field name="profile_id"/>
<field name="partner_id" filter_domain="[('partner_id', 'child_of', self)]"/>
<group expand="0" string="Group By...">
<filter string="Type" domain="" context="{'group_by': 'type'}"/>
<filter string="Profile" domain="" context="{'group_by': 'profile_id'}"/>
<filter string="Type" name="type" domain="" context="{'group_by': 'type'}"/>
<filter string="Profile" name="profile" domain="" context="{'group_by': 'profile_id'}"/>
</group>
</search>
</field>

View File

@ -2,7 +2,6 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from dateutil.relativedelta import relativedelta
from datetime import datetime
import logging
from odoo import api, fields, models, _
@ -236,14 +235,9 @@ class AccountAssetRemove(models.TransientModel):
[('asset_id', '=', asset.id), ('type', '=', 'create')])
last_depr_date = create_dl.line_date
period_number_days = (
datetime.strptime(first_date, '%Y-%m-%d') -
datetime.strptime(last_depr_date, '%Y-%m-%d')).days
date_remove = datetime.strptime(date_remove, '%Y-%m-%d')
period_number_days = (first_date - last_depr_date).days
new_line_date = date_remove + relativedelta(days=-1)
to_depreciate_days = (
new_line_date -
datetime.strptime(last_depr_date, '%Y-%m-%d')).days
to_depreciate_days = (new_line_date - last_depr_date).days
to_depreciate_amount = round(
float(to_depreciate_days) / float(period_number_days) *
first_to_depreciate_dl.amount, digits)