Ujjvala Collins (OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-account-asset-prorata_temporis_impl-uco
into lp:~openerp-dev/openobject-addons/trunk-account-asset.
Requested reviews:
Ujjvala Collins (OpenERP) (uco-openerp)
Mustufa Rangwala (Open ERP) (mra-tinyerp)
qdp (OpenERP) (qdp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-account-asset-prorata_temporis_impl-uco/+merge/61402
[IMP] account_asset:
----------------------------------
* implement the prorata temporis feature
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-account-asset-prorata_temporis_impl-uco/+merge/61402
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-account-asset.
=== modified file 'account_asset/account_asset.py'
--- account_asset/account_asset.py 2011-05-27 14:50:49 +0000
+++ account_asset/account_asset.py 2011-06-01 09:21:28 +0000
@@ -102,21 +102,29 @@
def compute_depreciation_board(self, cr, uid,ids, context=None):
depreciation_lin_obj = self.pool.get('account.asset.depreciation.line')
for asset in self.browse(cr, uid, ids, context=context):
- old_depreciation_line_ids = depreciation_lin_obj.search(cr, uid, [('asset_id', '=', asset.id), ('move_id', '=', False)])
- if old_depreciation_line_ids:
- depreciation_lin_obj.unlink(cr, uid, old_depreciation_line_ids, context=context)
- undone_dotation_number = asset.method_delay - len(asset.account_move_line_ids)
- residual_amount = asset.value_residual
+ undone_dotation_number = asset.method_delay
+ if asset.prorata and asset.method == 'linear':
+ undone_dotation_number += 1
+ amount_to_depr = residual_amount = asset.purchase_value - asset.salvage_value
depreciation_date = datetime.strptime(self._get_last_depreciation_date(cr, uid, [asset.id], context)[asset.id], '%Y-%m-%d')
day = depreciation_date.day
month = depreciation_date.month
year = depreciation_date.year
+ total_days = (year % 4) and 365 or 366
+ depr_vals = []
for i in range(1,undone_dotation_number+1):
if i == undone_dotation_number + 1:
amount = residual_amount
else:
if asset.method == 'linear':
- amount = asset.value_residual / undone_dotation_number
+ amount = amount_to_depr / undone_dotation_number
+ if asset.prorata:
+ amount = amount_to_depr / asset.method_delay
+ if i == 1:
+ days = total_days - float(depreciation_date.strftime('%j'))
+ amount = (amount_to_depr / asset.method_delay) / total_days * days
+ elif i == undone_dotation_number:
+ amount = (amount_to_depr / asset.method_delay) / total_days * (total_days - days)
else:
amount = residual_amount * asset.method_progress_factor
residual_amount -= amount
@@ -126,12 +134,19 @@
'sequence': i,
'name': str(asset.id) +'/'+ str(i),
'remaining_value': residual_amount,
- 'depreciated_value': asset.purchase_value - residual_amount,
+ 'depreciated_value': amount_to_depr - residual_amount,
'depreciation_date': depreciation_date.strftime('%Y-%m-%d'),
}
- depreciation_lin_obj.create(cr, uid, vals, context=context)
+ if asset.depreciation_line_ids:
+ depr_vals.append(vals)
+ else:
+ depreciation_lin_obj.create(cr, uid, vals, context=context)
month += asset.method_period
- depreciation_date = datetime(year + (month / 12), month % 12, day)
+ depreciation_date = datetime(year + (month / 12), (month % 12 or 12), day)
+ for vals in depr_vals:
+ for dep in asset.depreciation_line_ids:
+ if dep.sequence == vals['sequence'] and not dep.move_check:
+ depreciation_lin_obj.write(cr, uid, [dep.id], vals, context=context)
return True
def validate(self, cr, uid, ids, context={}):
@@ -201,6 +216,16 @@
'company_id': lambda self, cr, uid, context: self.pool.get('res.company')._company_default_get(cr, uid, 'account.asset.asset',context=context),
}
+ def _check_prorata(self, cr, uid, ids, context=None):
+ for asset in self.browse(cr, uid, ids, context=context):
+ if asset.prorata and asset.method != 'linear':
+ return False
+ return True
+
+ _constraints = [
+ (_check_prorata, '\nProrata temporis can be applied only for linear method.', ['prorata']),
+ ]
+
def onchange_category_id(self, cr, uid, ids, category_id, context=None):
res = {'value':{}}
asset_categ_obj = self.pool.get('account.asset.category')
@@ -338,7 +363,7 @@
move_line_obj = self.pool.get('account.move.line')
currency_obj = self.pool.get('res.currency')
for line in self.browse(cr, uid, ids, context=context):
- depreciation_date = time.strftime('%Y-%m-%d')
+ depreciation_date = line.asset_id.prorata and line.asset_id.purchase_date or time.strftime('%Y-%m-%d')
period_ids = period_obj.find(cr, uid, depreciation_date, context=context)
company_currency = line.asset_id.company_id.currency_id.id
current_currency = line.asset_id.currency_id.id
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp