Analytic account budget

bzr revid: rde-c7efb135e9890297b2ba82fb3ff35a0fcaf977c4
This commit is contained in:
rde 2007-01-08 11:08:37 +00:00
parent 92001a3df8
commit cc9ca29257
5 changed files with 193 additions and 1 deletions

View File

@ -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()

View File

@ -180,7 +180,6 @@
<field name="view_id" ref="account_analytic_line_extended_form" />
</record>
#
# Analytic Journal
#
@ -302,6 +301,80 @@
<menuitem name="Financial Management/Reporting/Analytic/This Month/Account Cost and Revenue by journal"
id="report_account_analytic_journal_print_month"
action="report_account_analytic_journal_tree_month"/>
# ---------------------------------------------------------
# Budgets
# ---------------------------------------------------------
<record model="ir.ui.view" id="view_account_analytic_budget_post_form">
<field name="name">account.analytic.budget.post.form</field>
<field name="model">account.analytic.budget.post</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Analytic Budget item">
<notebook>
<page string="Definition">
<field name="code" select="1"/>
<field name="name" select="1"/>
<field name="sens"/>
</page><page string="Dotations">
<button string="Spread" name="%(wizard_account_analytic_budget_spread)d" type="action"/>
<field name="dotation_ids" colspan="4" nolabel="1"/>
</page><page string="Accounts">
<field name="account_ids" colspan="4" nolabel="1"/>
</page>
</notebook>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_account_analytic_budget_post_tree">
<field name="name">account.analytic.budget.post.tree</field>
<field name="model">account.analytic.budget.post</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Analytic Budget item">
<field name="code"/>
<field name="name"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_account_analytic_budget_post_dotation_form">
<field name="name">account.analytic.budget.post.dotation.form</field>
<field name="model">account.analytic.budget.post.dotation</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Analytic Budget items expenses">
<field name="period_id"/>
<newline/>
<field name="quantity"/>
<field name="amount"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_analytic_budget_post_dotation_tree">
<field name="name">account.analytic.budget.post.dotation.tree</field>
<field name="model">account.analytic.budget.post.dotation</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Analytic Budget items expenses">
<field name="period_id"/>
<field name="quantity"/>
<field name="amount"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="open_account_analytic_budget_post_form">
<field name="name">account.analytic.budget.post.form</field>
<field name="res_model">account.analytic.budget.post</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_account_analytic_budget_post_form"/>
</record>
<menuitem name="Financial Management/Configuration/Analytic Accounts Budgets/Budget items" id="menu_account_analytic_budget_post_form" action="open_account_analytic_budget_post_form"/>
</data>
</terp>

View File

@ -0,0 +1,11 @@
<terp>
<data>
<!-- Budget -->
<wizard
string="Spread amount"
model="account.analytic.budget.post"
name="account.analytic.budget.spread"
menu="False"
id="wizard_account_analytic_budget_spread"/>
</data>
</terp>

View File

@ -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

View File

@ -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 = '''<?xml version="1.0"?>
<form string="Spread">
<field name="fiscalyear"/>
<newline/>
<field name="quantity"/>
<field name="amount"/>
</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')