trytonpsk-account_col/asset.py

110 lines
3.6 KiB
Python
Raw Permalink 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 dateutil.relativedelta import relativedelta
from trytond.pyson import Eval, Bool
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')
months = fields.Integer('Months 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)
asset_colgaap = fields.Many2One('account.asset', "Asset Colgaap",
domain=[('colgaap', '=', True)], states={
'invisible': Bool(Eval('colgaap'))}
)
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')
def on_change_start_date(self, name=None):
2022-07-08 16:12:16 +02:00
if self.kind:
self.end_date = self.start_date + relativedelta(months=self.kind.months)
2022-07-08 16:12:16 +02:00
@fields.depends('colgaap')
def on_change_with_kind(self, name=None):
return None
2022-11-18 22:26:12 +01:00
@staticmethod
def default_colgaap():
return False
2022-11-30 00:05:05 +01:00
def get_closing_move(self, account, date=None):
move = super(Asset, self).get_closing_move(account, date)
if move:
for line in move.lines:
if line.account.party_required:
line.party = self.company.party.id
return move
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([])
account_category = line.asset.product.account_category
if line.asset.asset_colgaap and move:
2022-11-18 22:26:12 +01:00
move.method = 'ifrs'
amount = 0
debit = 0
credit = 0
for l in line.asset.asset_colgaap.lines:
if line.date == l.date:
amount = l.depreciation - line.depreciation
if amount > 0:
debit = abs(amount)
else:
credit = abs(amount)
for line in move.lines:
if line.account.type.fixed_asset:
line.credit = credit
line.debit = debit
line.account = account_category.account_depreciation_diference
else:
line.credit = debit
line.debit = credit
line.account = account_category.account_expense_diference
2022-11-30 00:05:05 +01:00
line.party = self.company.party
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':
2022-11-30 00:05:05 +01:00
line.party = self.company.party
2020-04-07 15:34:03 +02:00
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])