1 # -*- coding: utf-8 -*-
2 # Copyright 2022 L'Heureux Cyclage
3 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
5 from openerp
.osv
import osv
6 from openerp
.osv
import orm
7 from openerp
.osv
import fields
10 class crossovered_budget_lines(orm
.Model
):
11 _inherit
= 'crossovered.budget.lines'
13 def _prac_amt(self
, cr
, uid
, ids
, context
=None):
14 """Calculate pratical amount even if there is no analytic account"""
19 account_obj
= self
.pool
.get('account.account')
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
]
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
29 if line
.analytic_account_id
.id:
30 res
= super(crossovered_budget_lines
, self
)._prac
_amt
(cr
, uid
, ids
, context
)
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]