[PYTHON] +allow to follow non analytic lines
[burette/account_budget_enhancement.git] / account_budget.py
1 # -*- coding: utf-8 -*-
2 # Copyright 2022 L'Heureux Cyclage
3 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4
5 from openerp.osv import osv
6 from openerp.osv import orm
7 from openerp.osv import fields
8
9
10 class crossovered_budget_lines(orm.Model):
11 _inherit = 'crossovered.budget.lines'
12
13 def _prac_amt(self, cr, uid, ids, context=None):
14 """Calculate pratical amount even if there is no analytic account"""
15 res = {}
16 result = 0.0
17 if context is None:
18 context = {}
19 account_obj = self.pool.get('account.account')
20
21 for line in self.browse(cr, uid, ids, context=context):
22 acc_ids = [x.id for x in line.general_budget_id.account_ids]
23 if not acc_ids:
24 raise osv.except_osv(_('Error!'),_("The Budget '%s' has no accounts!") % ustr(line.general_budget_id.name))
25 acc_ids = account_obj._get_children_and_consol(cr, uid, acc_ids, context=context)
26 date_to = line.date_to
27 date_from = line.date_from
28
29 if line.analytic_account_id.id:
30 res = super(crossovered_budget_lines, self)._prac_amt(cr, uid, ids, context)
31 else:
32 cr.execute("SELECT SUM(credit) - SUM(debit) FROM account_move_line WHERE (date "
33 "between to_date(%s,'yyyy-mm-dd') AND to_date(%s,'yyyy-mm-dd')) AND "
34 "account_id=ANY(%s)", (date_from, date_to,acc_ids,))
35 result = cr.fetchone()[0]
36 if result is None:
37 result = 0.00
38 res[line.id] = result
39
40 return res
41