2022-07-08 16:12:16 +02:00
|
|
|
from dataclasses import Field, fields
|
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
|
|
|
|
|
|
|
|
KINDLIST = {
|
|
|
|
'1': {'name': 'Constructions and buildings', 'days': 16425},
|
|
|
|
'2': {'name': 'Aqueduct, plant and networks', 'days': 14600},
|
|
|
|
'3': {'name': 'Communication channels', 'days': 14600},
|
|
|
|
'5': {'name': 'Fleet and air equipment', 'days': 10950},
|
|
|
|
'6': {'name': 'Fleet and railway equipment', 'days': 7300},
|
|
|
|
'7': {'name': 'Fleet and river equipment', 'days': 5475},
|
|
|
|
'8': {'name': 'Weapons and surveillance equipment', 'days': 3650},
|
|
|
|
'9': {'name': 'Electric equipment', 'days': 3650},
|
|
|
|
'10': {'name': 'Fleet and ground transportation equipment', 'days': 3650},
|
|
|
|
'11': {'name': 'Machinery, equipment', 'days': 3650},
|
|
|
|
'12': {'name': 'Furniture and fixtures', 'days': 3650},
|
|
|
|
'13': {'name': 'Scientific medical equipment', 'days': 2920},
|
|
|
|
'14': {'name': 'Containers, packaging and tools', 'days': 1825},
|
|
|
|
'15': {'name': 'Computer equipment', 'days': 1825},
|
|
|
|
'16': {'name': 'Data processing networks', 'days': 1825},
|
|
|
|
'17': {'name': 'Communication equipment', 'days': 1825},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class AssetLocation(ModelView, ModelSQL):
|
|
|
|
'Location Asset'
|
|
|
|
__name__ = 'account_col.asset_location'
|
|
|
|
|
|
|
|
name = fields.Char('name')
|
|
|
|
address = fields.Char('address')
|
|
|
|
|
|
|
|
|
2020-04-07 15:34:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Asset(metaclass=PoolMeta):
|
|
|
|
__name__ = 'account.asset'
|
|
|
|
|
2022-07-08 16:12:16 +02:00
|
|
|
kind = fields.Selection('get_kind_list','Kind')
|
|
|
|
location = fields.Many2One('account_col.asset_location', "Location")
|
|
|
|
type = fields.Selection([
|
|
|
|
('AFP' ,'Activo fijo propios'),
|
|
|
|
('CD', 'Comodato'),
|
|
|
|
('AC', 'Activo Controlado'),], 'Type')
|
|
|
|
code = fields.Char('Code')
|
|
|
|
|
|
|
|
@fields.depends('kind')
|
|
|
|
def on_change_with_end_date(self, name=None):
|
|
|
|
if self.kind:
|
|
|
|
print(self.kind)
|
|
|
|
days = KINDLIST[self.kind]['days']
|
|
|
|
return self.start_date + timedelta(days=days)
|
|
|
|
|
|
|
|
|
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([])
|
|
|
|
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 get_kind_list(cls):
|
|
|
|
return [(k,v['name']) for k,v in KINDLIST.items()]
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def create_lines(cls, assets):
|
|
|
|
for asset in assets:
|
|
|
|
if asset.type == 'AC':
|
|
|
|
continue
|
|
|
|
super(Asset, cls).create_lines([asset])
|
|
|
|
|
|
|
|
|