31
31
_name = "account.analytic.account"
32
32
_inherit = "account.analytic.account"
34
def _get_active(self, cr, uid, ids, field_name, args, context=None):
36
If date out of date_start/date of given analytic account, then account is inactive.
37
The comparison could be done via a date given in context.
40
cmp_date = datetime.date.today().strftime('%Y-%m-%d')
41
if context.get('date', False):
42
cmp_date = context.get('date')
43
for a in self.browse(cr, uid, ids):
45
if a.date_start > cmp_date:
47
if a.date and a.date <= cmp_date:
51
def _search_filter_active(self, cr, uid, ids, name, args, context=None):
53
UTP-410: Add the search on active/inactive CC
56
cmp_date = datetime.date.today().strftime('%Y-%m-%d')
57
if context.get('date', False):
58
cmp_date = context.get('date')
60
if x[0] == 'filter_active' and x[2] == True:
61
arg.append(('date_start', '<=', cmp_date))
63
arg.append(('date', '>', cmp_date))
64
arg.append(('date', '=', False))
65
elif x[0] == 'filter_active' and x[2] == False:
67
arg.append(('date_start', '>', cmp_date))
68
arg.append(('date', '<=', cmp_date))
71
def _search_closed_by_a_fp(self, cr, uid, ids, name, args, context=None):
73
UTP-423: Do not display analytic accounts linked to a soft/hard closed contract.
75
res = [('id', 'not in', [])]
76
if args and args[0] and len(args[0]) == 3:
78
raise osv.except_osv(_('Error'), _('Operator not supported yet!'))
79
# Search all fp_ids from soft_closed contract
81
FROM account_analytic_account a, financing_contract_contract fcc, financing_contract_funding_pool_line fcfl
82
WHERE fcfl.contract_id = fcc.id
83
AND fcfl.funding_pool_id = a.id
84
AND fcc.state in ('soft_closed', 'hard_closed');"""
86
sql_res = cr.fetchall()
88
aa_ids = self.is_blocked_by_a_contract(cr, uid, [x and x[0] for x in sql_res])
90
if isinstance(aa_ids, (int, long)):
92
res = [('id', 'not in', aa_ids)]
95
def _get_fake(self, cr, uid, ids, *a, **b):
96
return {}.fromkeys(ids, False)
98
def _search_intermission_restricted(self, cr, uid, ids, name, args, context=None):
104
raise osv.except_osv(_('Error'), _('Operator not supported on field intermission_restricted!'))
105
if not isinstance(arg[2], (list, tuple)):
106
raise osv.except_osv(_('Error'), _('Operand not supported on field intermission_restricted!'))
107
if arg[2] and (arg[2][0] or arg[2][1]):
109
intermission = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'analytic_distribution',
110
'analytic_account_project_intermission')[1]
113
if arg[2][2] == 'intermission':
114
newargs.append(('id', '=', intermission))
116
newargs.append(('id', '!=', intermission))
120
'name': fields.char('Name', size=128, required=True, translate=1),
35
'name': fields.char('Name', size=128, required=True),
121
36
'code': fields.char('Code', size=24),
122
37
'type': fields.selection([('view','View'), ('normal','Normal')], 'Type', help='If you select the View Type, it means you won\'t allow to create journal entries using that account.'),
123
38
'date_start': fields.date('Active from', required=True),
132
47
'destination_ids': many2many_notlazy('account.account', 'account_destination_link', 'destination_id', 'account_id', 'Accounts'),
133
48
'tuple_destination_account_ids': many2many_sorted('account.destination.link', 'funding_pool_associated_destinations', 'funding_pool_id', 'tuple_id', "Account/Destination"),
134
49
'tuple_destination_summary': fields.one2many('account.destination.summary', 'funding_pool_id', 'Destination by accounts'),
135
'filter_active': fields.function(_get_active, fnct_search=_search_filter_active, type="boolean", method=True, store=False, string="Show only active analytic accounts",),
136
'hide_closed_fp': fields.function(_get_active, fnct_search=_search_closed_by_a_fp, type="boolean", method=True, store=False, string="Linked to a soft/hard closed contract?"),
137
'intermission_restricted': fields.function(_get_fake, fnct_search=_search_intermission_restricted, type="boolean", method=True, store=False, string="Domain to restrict intermission cc"),
141
53
'date_start': lambda *a: (datetime.datetime.today() + relativedelta(months=-3)).strftime('%Y-%m-%d'),
142
54
'for_fx_gain_loss': lambda *a: False,
145
56
def _check_unicity(self, cr, uid, ids, context=None):
268
182
fp_ids.append(adl.get('funding_pool_ids'))
269
183
fp_ids = flatten(fp_ids)
270
184
args[i] = ('id', 'in', fp_ids)
271
res = super(analytic_account, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
185
return super(analytic_account, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
274
187
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):