From cc9ca2925778d3927ea7693f58325eea2c7b7426 Mon Sep 17 00:00:00 2001
From: rde <>
Date: Mon, 8 Jan 2007 11:08:37 +0000
Subject: [PATCH] Analytic account budget
bzr revid: rde-c7efb135e9890297b2ba82fb3ff35a0fcaf977c4
---
addons/account/project/project.py | 44 +++++++++++
addons/account/project/project_view.xml | 75 ++++++++++++++++++-
addons/account/project/project_wizard.xml | 11 +++
addons/account/project/wizard/__init__.py | 1 +
.../wizard_account_analytic_budget_spread.py | 63 ++++++++++++++++
5 files changed, 193 insertions(+), 1 deletion(-)
create mode 100644 addons/account/project/project_wizard.xml
create mode 100644 addons/account/project/wizard/wizard_account_analytic_budget_spread.py
diff --git a/addons/account/project/project.py b/addons/account/project/project.py
index 5af1aa708c5..614ac7e172e 100644
--- a/addons/account/project/project.py
+++ b/addons/account/project/project.py
@@ -176,3 +176,47 @@ class account_analytic_journal(osv.osv):
account_analytic_journal()
+# ---------------------------------------------------------
+# Budgets
+# ---------------------------------------------------------
+
+class account_analytic_budget_post(osv.osv):
+ _name = 'account.analytic.budget.post'
+ _description = 'Budget item'
+ _columns = {
+ 'code': fields.char('Code', size=64, required=True),
+ 'name': fields.char('Name', size=256, required=True),
+ 'sens': fields.selection( [('charge','Charge'), ('produit','Product')], 'Direction', required=True),
+ 'dotation_ids': fields.one2many('account.analytic.budget.post.dotation', 'post_id', 'Expenses'),
+ 'account_ids': fields.many2many('account.analytic.account', 'account_analytic_budget_rel', 'budget_id', 'account_id', 'Accounts'),
+ }
+ _defaults = {
+ 'sens': lambda *a: 'produit',
+ }
+
+ def spread(self, cr, uid, ids, fiscalyear_id=False, quantity=0.0, amount=0.0):
+
+ dobj = self.pool.get('account.analytic.budget.post.dotation')
+ for o in self.browse(cr, uid, ids):
+ # delete dotations for this post
+ dobj.unlink(cr, uid, dobj.search(cr, uid, [('post_id','=',o.id)]))
+
+ # create one dotation per period in the fiscal year, and spread the total amount/quantity over those dotations
+ fy = self.pool.get('account.fiscalyear').browse(cr, uid, [fiscalyear_id])[0]
+ num = len(fy.period_ids)
+ for p in fy.period_ids:
+ dobj.create(cr, uid, {'post_id': o.id, 'period_id': p.id, 'quantity': quantity/num, 'amount': amount/num})
+ return True
+account_analytic_budget_post()
+
+class account_analytic_budget_post_dotation(osv.osv):
+ _name = 'account.analytic.budget.post.dotation'
+ _description = "Budget item endowment"
+ _columns = {
+ 'name': fields.char('Name', size=64),
+ 'post_id': fields.many2one('account.analytic.budget.post', 'Item', select=True),
+ 'period_id': fields.many2one('account.period', 'Period'),
+ 'quantity': fields.float('Quantity', digits=(16,2)),
+ 'amount': fields.float('Amount', digits=(16,2)),
+ }
+account_analytic_budget_post_dotation()
diff --git a/addons/account/project/project_view.xml b/addons/account/project/project_view.xml
index 092da107594..77a999eb7a4 100644
--- a/addons/account/project/project_view.xml
+++ b/addons/account/project/project_view.xml
@@ -180,7 +180,6 @@
-
#
# Analytic Journal
#
@@ -302,6 +301,80 @@
+
+ # ---------------------------------------------------------
+ # Budgets
+ # ---------------------------------------------------------
+
+ account.analytic.budget.post.form
+ account.analytic.budget.post
+ form
+
+
+
+
+
+ account.analytic.budget.post.tree
+ account.analytic.budget.post
+ tree
+
+
+
+
+
+
+
+
+
+
+ account.analytic.budget.post.dotation.form
+ account.analytic.budget.post.dotation
+ form
+
+
+
+
+
+
+ account.analytic.budget.post.dotation.tree
+ account.analytic.budget.post.dotation
+ tree
+
+
+
+
+
+
+
+
+
+
+ account.analytic.budget.post.form
+ account.analytic.budget.post
+ form
+
+
+
+
+
diff --git a/addons/account/project/project_wizard.xml b/addons/account/project/project_wizard.xml
new file mode 100644
index 00000000000..71c5c7193a5
--- /dev/null
+++ b/addons/account/project/project_wizard.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
diff --git a/addons/account/project/wizard/__init__.py b/addons/account/project/wizard/__init__.py
index 10379ff99e4..769f5be74a4 100644
--- a/addons/account/project/wizard/__init__.py
+++ b/addons/account/project/wizard/__init__.py
@@ -31,4 +31,5 @@ import wizard_account_analytic_inverted_balance_report
import wizard_account_analytic_cost_ledger_report
import wizard_account_analytic_cost_ledger_for_journal_report
import wizard_account_analytic_year_to_date_check
+import wizard_account_analytic_budget_spread
diff --git a/addons/account/project/wizard/wizard_account_analytic_budget_spread.py b/addons/account/project/wizard/wizard_account_analytic_budget_spread.py
new file mode 100644
index 00000000000..de6c2bd28a2
--- /dev/null
+++ b/addons/account/project/wizard/wizard_account_analytic_budget_spread.py
@@ -0,0 +1,63 @@
+##############################################################################
+#
+# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+import wizard
+import netsvc
+
+_spread_form = '''
+
'''
+
+_spread_fields = {
+ 'fiscalyear': {'string':'Fiscal Year', 'type':'many2one', 'relation':'account.fiscalyear', 'required':True},
+ 'quantity': {'string':'Quantity', 'type':'float', 'digits':(16,2)},
+ 'amount': {'string':'Amount', 'type':'float', 'digits':(16,2)},
+}
+
+class wizard_account_analytic_budget_spread(wizard.interface):
+ def _spread(self, cr, uid, data, context):
+ service = netsvc.LocalService("object_proxy")
+ form = data['form']
+ res = service.execute(cr.dbname, uid, 'account.analytic.budget.post', 'spread', data['ids'], form['fiscalyear'], form['quantity'], form['amount'])
+ return {}
+
+ states = {
+ 'init': {
+ 'actions': [],
+ 'result': {'type':'form', 'arch':_spread_form, 'fields':_spread_fields, 'state':[('end','Cancel'),('spread','Spread')]}
+ },
+ 'spread': {
+ 'actions': [_spread],
+ 'result': {'type':'state', 'state':'end'}
+ }
+ }
+wizard_account_analytic_budget_spread('account.analytic.budget.spread')
+