Skip to content

Commit

Permalink
[IMP] l10n_es_account_asset: Incluido nuevo método de depreciación po…
Browse files Browse the repository at this point in the history
…r porcentaje fijo.
  • Loading branch information
Pedro M. Baeza committed May 28, 2013
1 parent 58601b4 commit b25ee30
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 16 deletions.
1 change: 1 addition & 0 deletions l10n_es_account_asset/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
regulaciones españolas:
* Cambia el método de cálculo para el prorrateo temporal.
* Añade un nuevo método de cálculo para porcentaje fijo por periodo.
* Añade la opción de trasladar la depreciación al final del periodo.
""",
"website" : "http://www.serviciosbaeza.com",
Expand Down
90 changes: 81 additions & 9 deletions l10n_es_account_asset/account_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,105 @@
import datetime
from osv import osv, fields

class account_asset_category(osv.osv):
_inherit = 'account.asset.category'
_name = 'account.asset.category'

_columns = {
'ext_method_time': fields.selection([('number','Number of Depreciations'),('end','Ending Date'),('percentage','Fixed percentage')], 'Time Method', required=True,
help="Choose the method to use to compute the dates and number of depreciation lines.\n"\
" * Number of Depreciations: Fix the number of depreciation lines and the time between 2 depreciations.\n" \
" * Ending Date: Choose the time between 2 depreciations and the date the depreciations won't go beyond.\n" \
" * Fixed percentage: Choose the time between 2 depreciations and the percentage to depreciate."),
'method_percentage': fields.integer('Depreciation percentage'),
}

_defaults = {
'method_percentage': 100,
}

_sql_constraints = [
('method_percentage', ' CHECK (method_percentage > 0 and method_percentage <= 100)', 'Wrong percentage!'),
]

def onchange_ext_method_time(self, cr, uid, ids, ext_method_time, context=None):
res = {'value':{}}
res['value']['method_time'] = 'end' if ext_method_time == 'end' else 'number'
return res


class account_asset_asset(osv.osv):
_inherit = 'account.asset.asset'
_name = 'account.asset.asset'
_description = 'Asset'

_columns = {
'move_end_period': fields.boolean("At the end of the period", help='Move the depreciation entry at the end of the period. If the period are 12 months, it is put on 31st of December, and in the end of the month in other case.'),
# Hay que definir un nuevo campo y jugar con los valores del antiguo (method_time) para pasar el constraint _check_prorata y no tener que modificar mucho código base
'ext_method_time': fields.selection([('number','Number of Depreciations'),('end','Ending Date'),('percentage','Fixed percentage')], 'Time Method', required=True,
help="Choose the method to use to compute the dates and number of depreciation lines.\n"\
" * Number of Depreciations: Fix the number of depreciation lines and the time between 2 depreciations.\n" \
" * Ending Date: Choose the time between 2 depreciations and the date the depreciations won't go beyond.\n" \
" * Fixed percentage: Choose the time between 2 depreciations and the percentage to depreciate."),
'method_percentage': fields.integer('Depreciation percentage'),
}

_defaults = {
'method_percentage': 100,
'move_end_period': True,
}

_sql_constraints = [
('method_percentage', ' CHECK (method_percentage > 0 and method_percentage <= 100)', 'Wrong percentage!'),
]

def onchange_ext_method_time(self, cr, uid, ids, ext_method_time, context=None):
res = {'value':{}}
res['value']['method_time'] = 'end' if ext_method_time == 'end' else 'number'
return res

def onchange_category_id(self, cr, uid, ids, category_id, context=None):
res = super(account_asset_asset, self).onchange_category_id(cr, uid, ids, category_id, context=context)
if category_id:
category_obj = self.pool.get('account.asset.category').browse(cr, uid, category_id, context=context)
res['value']['ext_method_time'] = category_obj.ext_method_time
res['value']['method_percentage'] = category_obj.method_percentage
return res

def _compute_board_undone_dotation_nb(self, cr, uid, asset, depreciation_date, total_days, context=None):
val = super(account_asset_asset, self)._compute_board_undone_dotation_nb(cr, uid, asset, depreciation_date, total_days, context=context)
if depreciation_date.day == 1 and depreciation_date.month == 1:
# Quitar una depreciación del nº total si el activo se compró el 1 de enero,
# ya que ese año sería completo
val -= 1
return val
if asset.ext_method_time == 'percentage':
number = 0
percentage = 100.0
while percentage > 0:
if number == 0 and asset.prorata:
days = (total_days - float(depreciation_date.strftime('%j'))) + 1
percentage -= asset.method_percentage * days / total_days
else:
percentage -= asset.method_percentage
number += 1
return number
else:
val = super(account_asset_asset, self)._compute_board_undone_dotation_nb(cr, uid, asset, depreciation_date, total_days, context=context)
if depreciation_date.day == 1 and depreciation_date.month == 1:
# Quitar una depreciación del nº total si el activo se compró el 1 de enero, ya que ese año sería completo
val -= 1
return val

def _compute_board_amount(self, cr, uid, asset, i, residual_amount, amount_to_depr, undone_dotation_number, posted_depreciation_line_ids, total_days, depreciation_date, context=None):
if asset.method == 'linear' and asset.prorata and i != undone_dotation_number:
if asset.ext_method_time == 'percentage':
# Nuevo tipo de cálculo
if i == undone_dotation_number:
return residual_amount
else:
if i == 1 and asset.prorata:
days = (total_days - float(depreciation_date.strftime('%j'))) + 1
percentage = asset.method_percentage * days / total_days
else:
percentage = asset.method_percentage
return amount_to_depr * percentage / 100
elif asset.method == 'linear' and asset.prorata and i != undone_dotation_number:
# Caso especial de cálculo que cambia
amount = amount_to_depr / asset.method_number
if i == 1:
year = depreciation_date.year
days = (total_days - float(depreciation_date.strftime('%j'))) + 1
amount *= days / total_days
return amount
Expand Down
39 changes: 39 additions & 0 deletions l10n_es_account_asset/account_asset_view.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
<openerp>
<data>

<record model="ir.ui.view" id="view_account_asset_category_form_l10n_es">
<field name="name">account.asset.category.form.l10n_es</field>
<field name="model">account.asset.category</field>
<field name="inherit_id" ref="account_asset.view_account_asset_category_form"/>
<field name="arch" type="xml">
<field name="method_time" position="attributes">
<attribute name="attrs">{'invisible': True}</attribute>
</field>
<field name="method_time" position="after">
<field name="ext_method_time" on_change="onchange_ext_method_time(ext_method_time)"/>
<field name="method_percentage" attrs="{'invisible':[('ext_method_time','!=','percentage')], 'required':[('ext_method_time','=','percentage')]}"/>
</field>
<field name="method_number" position="attributes">
<attribute name="attrs">{'invisible':[('ext_method_time','!=','number')], 'required':[('ext_method_time','=','number')]}</attribute>
</field>
<field name="method_end" position="attributes">
<attribute name="attrs">{'invisible':[('ext_method_time','!=','end')], 'required':[('ext_method_time','=','end')]}</attribute>
</field>
</field>
</record>

<record model="ir.ui.view" id="view_account_asset_asset_form_l10n_es">
<field name="name">account.asset.asset.form.l10n_es</field>
<field name="model">account.asset.asset</field>
<field name="inherit_id" ref="account_asset.view_account_asset_asset_form"/>
<field name="arch" type="xml">
<label for="method_time" position="replace">
<label for="ext_method_time"/>
</label>
<field name="method_time" position="attributes">
<attribute name="attrs">{'invisible': True}</attribute>
</field>
<field name="method_time" position="after">
<field name="ext_method_time" on_change="onchange_ext_method_time(ext_method_time)"/>
</field>
<field name="method_number" position="after">
<field name="method_percentage" attrs="{'invisible':[('ext_method_time','!=','percentage')], 'required':[('ext_method_time','=','percentage')]}"/>
</field>
<field name="method_number" position="attributes">
<attribute name="attrs">{'invisible':[('ext_method_time','!=','number')], 'required':[('ext_method_time','=','number')]}</attribute>
</field>
<field name="method_end" position="attributes">
<attribute name="attrs">{'invisible':[('ext_method_time','!=','end')], 'required':[('ext_method_time','=','end')]}</attribute>
</field>
<field name="prorata" position="after">
<field name="move_end_period"/>
</field>
Expand Down
69 changes: 62 additions & 7 deletions l10n_es_account_asset/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,82 @@ msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-05-24 15:25+0000\n"
"PO-Revision-Date: 2013-05-24 15:25+0000\n"
"Last-Translator: <>\n"
"POT-Creation-Date: 2013-05-28 11:18+0000\n"
"PO-Revision-Date: 2013-05-28 13:19+0100\n"
"Last-Translator: Pedro Manuel Baeza <pedro.baeza@serviciosbaeza.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"

#. module: l10n_es_account_asset
#: selection:account.asset.asset,ext_method_time:0
#: selection:account.asset.category,ext_method_time:0
msgid "Ending Date"
msgstr "Fecha final"

#. module: l10n_es_account_asset
#: sql_constraint:account.asset.asset:0
#: sql_constraint:account.asset.category:0
msgid "Wrong percentage!"
msgstr "¡Porcentaje incorrecto!"

#. module: l10n_es_account_asset
#: help:account.asset.asset,move_end_period:0
msgid "Move the depreciation entry at the end of the period. If the period are 12 months, it is put on 31st of December, and in the end of the month in other case."
msgstr "Mueve el apunte de depreciación al final del periodo. Si el periodo es de 12 meses, lo pone el 31 de diciembre, y al final del mes en el resto de casos."

#. module: l10n_es_account_asset
#: field:account.asset.asset,move_end_period:0
msgid "At the end of the period"
msgstr "Al final del periodo"
#: help:account.asset.asset,ext_method_time:0
#: help:account.asset.category,ext_method_time:0
msgid ""
"Choose the method to use to compute the dates and number of depreciation lines.\n"
" * Number of Depreciations: Fix the number of depreciation lines and the time between 2 depreciations.\n"
" * Ending Date: Choose the time between 2 depreciations and the date the depreciations won't go beyond.\n"
" * Fixed percentage: Choose the time between 2 depreciations and the percentage to depreciate."
msgstr ""
"Escoja el método usado para calcular las fechas y número de líneas de depreciación:\n"
" * Número de depreciaciones: Ajusta el número de líneas de depreciación y el periodo entre 2 depreciaciones.\n"
" * Fecha final: Escoja el periodo entre 2 amortizaciones y la fecha a partir de la cual no habrá depreciaciones.\n"
" * Porcentaje fijo: Escoja el periodo entre 2 amortizaciones y el porcentaje a depreciar en ese periodo."

#. module: l10n_es_account_asset
#: model:ir.model,name:l10n_es_account_asset.model_account_asset_asset
msgid "Asset"
msgstr "Activo"

#. module: l10n_es_account_asset
#: model:ir.model,name:l10n_es_account_asset.model_account_asset_category
msgid "Asset category"
msgstr "Categoría de activo"

#. module: l10n_es_account_asset
#: selection:account.asset.asset,ext_method_time:0
#: selection:account.asset.category,ext_method_time:0
msgid "Number of Depreciations"
msgstr "Número de depreciaciones"

#. module: l10n_es_account_asset
#: selection:account.asset.asset,ext_method_time:0
#: selection:account.asset.category,ext_method_time:0
msgid "Fixed percentage"
msgstr "Porcentaje fijo"

#. module: l10n_es_account_asset
#: field:account.asset.asset,move_end_period:0
msgid "At the end of the period"
msgstr "Al final del periodo"

#. module: l10n_es_account_asset
#: field:account.asset.asset,method_percentage:0
#: field:account.asset.category,method_percentage:0
msgid "Depreciation percentage"
msgstr "Porcentaje de depreciación"

#. module: l10n_es_account_asset
#: field:account.asset.asset,ext_method_time:0
#: field:account.asset.category,ext_method_time:0
msgid "Time Method"
msgstr "Método de tiempo"

0 comments on commit b25ee30

Please sign in to comment.