From: Ludovic CHEVALIER Date: Fri, 4 Mar 2022 14:28:08 +0000 (+0100) Subject: [PYTHON] +budget customization X-Git-Tag: production~12 X-Git-Url: http://git.cyclocoop.org/?p=burette%2Flhc.git;a=commitdiff_plain;h=66a75bcaa27668c4af43efffa8286997eb046743 [PYTHON] +budget customization --- diff --git a/__openerp__.py b/__openerp__.py index c0aee7c..d5d5ed5 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -2,7 +2,7 @@ ############################################################################## # # lhc module for OpenERP, Customize OpenERP for L'Heureux Cyclage Copyright -# (C) 2013-2020 L'Heureux Cyclage () +# (C) 2013-2022 L'Heureux Cyclage () # # This file is a part of lhc_custom_oe # @@ -33,12 +33,14 @@ Custom module for L'Heureux Cyclage - Customing for professionnal training activities; - Event management optimization; - Add some partners fields; +- Budget module customization; - … """, 'author': 'L\'Heureux Cyclage', 'website': 'http://www.heureux-cyclage.org', 'depends': [ 'account', + 'account_budget', 'analytic', 'document', 'event', diff --git a/lhc.py b/lhc.py index de5776a..494773c 100644 --- a/lhc.py +++ b/lhc.py @@ -2,7 +2,7 @@ ############################################################################## # # lhc module for OpenERP, Customize OpenERP for L'Heureux Cyclage Copyright -# (C) 2013-2020 L'Heureux Cyclage () +# (C) 2013-2022 L'Heureux Cyclage () # # This file is a part of lhc_custom_oe # @@ -24,6 +24,7 @@ from openerp.osv import osv from openerp.osv import orm from openerp.osv import fields +from openerp.tools.translate import _ import openerp.addons.decimal_precision as dp @@ -145,7 +146,7 @@ class event_registration(orm.Model): } def onchange_contact_id(self, cr, uid, ids, contact, partner, context=None): - """Concat phone with mobile phone if exist. If mobile exist and not + """Contcat phone with mobile phone if exist. If mobile exist and not phone, add mobile number""" vals = super(event_registration, self).onchange_contact_id(cr, uid, ids, contact, partner, context) addr_obj = self.pool.get('res.partner') @@ -160,4 +161,37 @@ class event_registration(orm.Model): return vals +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 + + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: