trytonpsk-account_col/asset.py

72 lines
2.1 KiB
Python
Raw Normal View History

2021-08-14 23:58:07 +02:00
from trytond.pool import Pool, PoolMeta
2022-07-08 16:12:16 +02:00
from trytond.model import ModelView, ModelSQL, fields
from datetime import timedelta
2022-11-18 22:26:12 +01:00
from trytond.pyson import Eval
2022-07-08 16:12:16 +02:00
class AssetLocation(ModelView, ModelSQL):
'Location Asset'
__name__ = 'account_col.asset_location'
name = fields.Char('name')
address = fields.Char('address')
2022-07-12 17:42:11 +02:00
class DepreciationKind(ModelView, ModelSQL):
'Depreciation Kind'
__name__ = 'account_col.depreciation_kind'
name = fields.Char('Name')
years = fields.Integer('Years Depreciation')
2022-11-18 22:26:12 +01:00
colgaap = fields.Boolean('Colgaap')
@staticmethod
def default_colgaap():
return False
2020-04-07 15:34:03 +02:00
class Asset(metaclass=PoolMeta):
__name__ = 'account.asset'
2022-11-18 22:26:12 +01:00
kind = fields.Many2One('account_col.depreciation_kind', 'Kind',
required=True, domain=[('colgaap', '=', Eval('colgaap', False))])
2022-07-08 16:12:16 +02:00
location = fields.Many2One('account_col.asset_location', "Location")
type = fields.Selection([
2022-11-02 14:54:48 +01:00
('AFP', 'Activo fijo propios'),
('CD', 'Comodato'),
('AC', 'Activo Controlado')
], 'Type', required=True)
2022-07-08 16:12:16 +02:00
code = fields.Char('Code')
2022-11-18 22:26:12 +01:00
colgaap = fields.Boolean('Colgaap')
2022-07-08 16:12:16 +02:00
2022-11-18 22:26:12 +01:00
@fields.depends('kind', 'start_date')
2022-07-08 16:12:16 +02:00
def on_change_with_end_date(self, name=None):
if self.kind:
2022-07-12 17:42:11 +02:00
days = 365 * self.kind.years
2022-11-02 14:54:48 +01:00
return self.start_date + timedelta(days=days)
2022-07-08 16:12:16 +02:00
2022-11-18 22:26:12 +01:00
@staticmethod
def default_colgaap():
return False
2020-04-07 15:34:03 +02:00
def get_move(self, line):
move = super(Asset, self).get_move(line)
Company = Pool().get('company.company')
company = Company.search([])
2022-11-18 22:26:12 +01:00
if line.asset.colgaap:
move.method = 'colgaap'
else:
move.method = 'ifrs'
2020-04-07 15:34:03 +02:00
if move:
for line in move.lines:
2021-08-05 19:26:59 +02:00
if line.account.type.statement == 'income':
2020-04-07 15:34:03 +02:00
line.party = company[0].party
return move
2022-07-08 16:12:16 +02:00
@classmethod
def create_lines(cls, assets):
for asset in assets:
2022-07-12 17:42:11 +02:00
if asset.type == 'AC' or asset.type == 'CD':
2022-07-08 16:12:16 +02:00
continue
super(Asset, cls).create_lines([asset])