From: Ludovic CHEVALIER Date: Wed, 11 May 2022 11:15:56 +0000 (+0200) Subject: [PYTHON] +allow to follow non analytic lines X-Git-Url: http://git.cyclocoop.org/data/%24%7Bnav_urls/projects/%40%20%27info_date_publication_anterieure%27%20=%3E%20%27Previously%20published%20on:%27%2C%20%27info_date_referencement%27%20=%3E%20%27THIS%20SITE%20REFERENCED%20ON:%27%2C%20%27info_derniere_etape%27%20=%3E%20%27Done%21%27%2C-%27info_derniers_articles_publies%27%20=%3E%20%27Your%20most%20recently%20published%20articles%27%2C-%27info_desactiver_messagerie_personnelle%27%20=%3E%20%27You%20can%20enable%20or%20disable%20your%20personal%20messaging%20on%20this%20site.%27%2C%20%27info_descriptif%27%20=%3E%20%27Description:%27%2C%20%27info_desinstaller_plugin%27%20=%3E%20%27%20deactivates%20the%20plugin%20and%20deletes%20the%20data%27%2C%20%27info_discussion_cours%27%20=%3E%20%27Current%20discussions%27%2C%40%40%20-332%2C7%20%20284%2C6%20%40%40%20Do%20not%20submit%20this%20import%20request.%3Cp%3EFor%20more%20information%2C%20please%20see%20%3Ca%20href=?a=commitdiff_plain;p=burette%2Faccount_budget_enhancement.git [PYTHON] +allow to follow non analytic lines --- diff --git a/account_budget.py b/account_budget.py new file mode 100644 index 0000000..187cf29 --- /dev/null +++ b/account_budget.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 L'Heureux Cyclage +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.osv import osv +from openerp.osv import orm +from openerp.osv import fields + + +class crossovered_budget_lines(orm.Model): + _inherit = 'crossovered.budget.lines' + + def _prac_amt(self, cr, uid, ids, context=None): + """Calculate pratical amount even if there is no analytic account""" + res = {} + result = 0.0 + if context is None: + context = {} + account_obj = self.pool.get('account.account') + + for line in self.browse(cr, uid, ids, context=context): + acc_ids = [x.id for x in line.general_budget_id.account_ids] + if not acc_ids: + raise osv.except_osv(_('Error!'),_("The Budget '%s' has no accounts!") % ustr(line.general_budget_id.name)) + acc_ids = account_obj._get_children_and_consol(cr, uid, acc_ids, context=context) + date_to = line.date_to + date_from = line.date_from + + if line.analytic_account_id.id: + res = super(crossovered_budget_lines, self)._prac_amt(cr, uid, ids, context) + else: + cr.execute("SELECT SUM(credit) - SUM(debit) FROM account_move_line WHERE (date " + "between to_date(%s,'yyyy-mm-dd') AND to_date(%s,'yyyy-mm-dd')) AND " + "account_id=ANY(%s)", (date_from, date_to,acc_ids,)) + result = cr.fetchone()[0] + if result is None: + result = 0.00 + res[line.id] = result + + return res +