Report account module

Analytic report

bzr revid: pinky-0f1fc9241566037f99ddd0c942a56aee4dc983a1
This commit is contained in:
pinky 2006-12-18 14:16:10 +00:00
parent 4031d4a566
commit 1ceb037e4a
8 changed files with 329 additions and 48 deletions

View File

@ -0,0 +1,106 @@
##############################################################################
#
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# $Id: project.py 1005 2005-07-25 08:41:42Z nicoe $
#
# 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.
#
##############################################################################
from osv import fields,osv
class account_analytic_to_invoice(osv.osv):
_name = "account"
_description = "Cases by user and section"
_auto = False
_columns = {
'name': fields.date('Month', readonly=True),
'user_id':fields.many2one('res.users', 'User', readonly=True, relate=True),
'section_id':fields.many2one('crm.case.section', 'Section', readonly=True, relate=True),
'amount_revenue': fields.float('Est.Revenue', readonly=True),
'amount_costs': fields.float('Est.Cost', readonly=True),
'amount_revenue_prob': fields.float('Est. Rev*Prob.', readonly=True),
'nbr': fields.integer('# of Cases', readonly=True),
'probability': fields.float('Avg. Probability', readonly=True),
'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
'delay_close': fields.integer('Delay to close', readonly=True),
}
_order = 'name desc, user_id, section_id'
def init(self, cr):
cr.execute("""
create or replace view report_crm_case_user as (
select
min(c.id) as id,
substring(c.create_date for 7)||'-01' as name,
c.state,
c.user_id,
c.section_id,
count(*) as nbr,
sum(planned_revenue) as amount_revenue,
sum(planned_cost) as amount_costs,
sum(planned_revenue*probability)::decimal(16,2) as amount_revenue_prob,
avg(probability)::decimal(16,2) as probability,
to_char(avg(date_closed-c.create_date), 'DD"d" HH12:MI:SS') as delay_close
from
crm_case c
group by substring(c.create_date for 7), c.state, c.user_id, c.section_id
)""")
report_crm_case_user()
class report_crm_case_categ(osv.osv):
_name = "report.crm.case.categ"
_description = "Cases by section and category"
_auto = False
_columns = {
'name': fields.date('Month', readonly=True),
'categ_id':fields.many2one('crm.case.categ', 'Category', readonly=True, relate=True),
'section_id':fields.many2one('crm.case.section', 'Section', readonly=True, relate=True),
'amount_revenue': fields.float('Est.Revenue', readonly=True),
'amount_costs': fields.float('Est.Cost', readonly=True),
'amount_revenue_prob': fields.float('Est. Rev*Prob.', readonly=True),
'nbr': fields.integer('# of Cases', readonly=True),
'probability': fields.float('Avg. Probability', readonly=True),
'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
'delay_close': fields.integer('Delay Close', readonly=True),
}
_order = 'name desc, categ_id, section_id'
def init(self, cr):
cr.execute("""
create or replace view report_crm_case_categ as (
select
min(c.id) as id,
substring(c.create_date for 7)||'-01' as name,
c.state,
c.categ_id,
c.section_id,
count(*) as nbr,
sum(planned_revenue) as amount_revenue,
sum(planned_cost) as amount_costs,
sum(planned_revenue*probability)::decimal(16,2) as amount_revenue_prob,
avg(probability)::decimal(16,2) as probability,
to_char(avg(date_closed-c.create_date), 'DD"d" HH12:MI:SS') as delay_close
from
crm_case c
group by substring(c.create_date for 7), c.state, c.categ_id, c.section_id
)""")
report_crm_case_categ()

View File

@ -215,7 +215,7 @@ class product_template(osv.osv):
'uom_id': _get_uom_id,
'uom_po_id': _get_uom_id,
#'uom_price_id' : _get_uom_id,
'uos_id' : _get_uom_id,
#'uos_id' : _get_uom_id,
'uos_coeff' : lambda *a: 1.0,
'mes_type' : lambda *a: 'fixed',
}

View File

@ -0,0 +1,30 @@
##############################################################################
#
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# $Id: __init__.py 1005 2005-07-25 08:41:42Z nicoe $
#
# 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 report_account

View File

@ -0,0 +1,14 @@
{
"name" : "Account Reporting - Reporting",
"version" : "1.0",
"author" : "Tiny",
"website" : "http://tinyerp.com",
"depends" : ["account"],
"category" : "Generic Modules/Accounting",
"description": "A module that adds new reports based on the account module.",
"init_xml" : [],
"demo_xml" : [],
"update_xml" : ["report_account_view.xml"],
"active": False,
"installable": True
}

View File

@ -0,0 +1,68 @@
##############################################################################
#
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# $Id: project.py 1005 2005-07-25 08:41:42Z nicoe $
#
# 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.
#
##############################################################################
from osv import fields,osv
class report_account_receivable(osv.osv):
_name = "report.account.receivable"
_description = "Receivable accounts"
_auto = False
_columns = {
'name': fields.date('Month', readonly=True),
'user_id':fields.many2one('res.users', 'User', readonly=True, relate=True),
'section_id':fields.many2one('crm.case.section', 'Section', readonly=True, relate=True),
'amount_revenue': fields.float('Est.Revenue', readonly=True),
'amount_costs': fields.float('Est.Cost', readonly=True),
'amount_revenue_prob': fields.float('Est. Rev*Prob.', readonly=True),
'nbr': fields.integer('# of Cases', readonly=True),
'probability': fields.float('Avg. Probability', readonly=True),
'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
'delay_close': fields.integer('Delay to close', readonly=True),
}
_order = 'name desc, user_id, section_id'
def init(self, cr):
cr.execute("""
create or replace view report_crm_case_user as (
select
min(c.id) as id,
substring(c.create_date for 7)||'-01' as name,
c.state,
c.user_id,
c.section_id,
count(*) as nbr,
sum(planned_revenue) as amount_revenue,
sum(planned_cost) as amount_costs,
sum(planned_revenue*probability)::decimal(16,2) as amount_revenue_prob,
avg(probability)::decimal(16,2) as probability,
to_char(avg(date_closed-c.create_date), 'DD"d" HH12:MI:SS') as delay_close
from
crm_case c
group by substring(c.create_date for 7), c.state, c.user_id, c.section_id
)""")
report_crm_case_user()

View File

@ -0,0 +1,66 @@
<?xml version="1.0"?>
<terp>
<data>
#
# Cases by user and section
#
<record model="ir.ui.view" id="view_crm_case_user_tree">
<field name="name">report.crm.case.user.tree</field>
<field name="model">report.crm.case.user</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Cases by User and Section">
<field name="name"/>
<field name="user_id"/>
<field name="section_id"/>
<field name="nbr"/>
<field name="delay_close"/>
<field name="amount_revenue"/>
<field name="amount_costs"/>
<field name="amount_revenue_prob"/>
<field name="probability"/>
<field name="state"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_crm_case_user_form">
<field name="name">report.crm.case.user.form</field>
<field name="model">report.crm.case.user</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Cases by User and Section">
<field name="name" select="1"/>
<field name="user_id" select="1"/>
<field name="section_id" select="1"/>
<field name="nbr" select="1"/>
<field name="state" select="1"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_crm_case_user_graph">
<field name="name">report.crm.case.user.graph</field>
<field name="model">report.crm.case.user</field>
<field name="type">graph</field>
<field name="arch" type="xml">
<graph string="Cases by User and Section" type="bar">
<field name="user_id" group="True"/>
<field name="nbr" operator="+"/>
</graph>
</field>
</record>
<record model="ir.actions.act_window" id="action_report_crm_case_user_tree_month">
<field name="name">report.crm.case.user.tree</field>
<field name="res_model">report.crm.case.user</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="domain">[('name','=',time.strftime('%Y-%m-01'))]</field>
</record>
<menuitem name="CRM &amp; SRM/Reporting/This Month/Cases by user and section" action="action_report_crm_case_user_tree_month" id="menu_crm_case_user_tree_month"/>
</data>
</terp>

View File

@ -30,38 +30,36 @@
from osv import fields,osv
class report_analytic_account_close(osv.osv):
_name = "report.analytic.account.close"
_description = "Analytic account to close"
_auto = False
_columns = {
'name': fields.many2one('account.analytic.account', 'Analytic account', readonly=True),
'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
'quantity': fields.float('Quantity', readonly=True),
'quantity_max': fields.float('Max. Quantity', readonly=True),
'balance': fields.float('Balance', readonly=True),
'date_deadline': fields.date('Deadline', readonly=True),
}
def init(self, cr):
cr.execute("""
create or replace view report_crm_case_user as (
select
l.account_id as id,
l.account_id as name,
sum(l.unit_amount) as quantity,
sum(l.amount) as balance,
a.partner_id as partner_id,
a.quantity_max as quantity_max,
a.date as date_deadline
from
account_analytic_line l
left join
account_analytic_account a on (l.account_id=a.id)
where
a.state='open'
group by
l.account_id,a.quantity_max,a.date,a.partner_id
having
sum(l.unit_amount)>=a.quantity_max or
a.date <= current_date
)""")
_name = "report.analytic.account.close"
_description = "Analytic account to close"
_auto = False
_columns = {
'name': fields.many2one('account.analytic.account', 'Analytic account', readonly=True),
'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
'quantity': fields.float('Quantity', readonly=True),
'quantity_max': fields.float('Max. Quantity', readonly=True),
'balance': fields.float('Balance', readonly=True),
'date_deadline': fields.date('Deadline', readonly=True),
}
def init(self, cr):
cr.execute("""
create or replace view report_analytic_account_close as (
select
a.id as id,
a.id as name,
sum(l.unit_amount) as quantity,
sum(l.amount) as balance,
a.partner_id as partner_id,
a.quantity_max as quantity_max,
a.date as date_deadline
from
account_analytic_line l
right join
account_analytic_account a on (l.account_id=a.id)
group by
a.id,a.quantity_max,a.date,a.partner_id
having
(a.quantity_max>0 and (sum(l.unit_amount)>=a.quantity_max)) or
a.date <= current_date
)""")
report_analytic_account_close()

View File

@ -6,12 +6,12 @@
# Analytic accounts to close
#
<record model="ir.ui.view" id="view_analytic_account_form">
<field name="name">report.analytic.account.form</field>
<field name="model">report.analytic.account</field>
<record model="ir.ui.view" id="view_analytic_account_close_form">
<field name="name">report.analytic.account.close.form</field>
<field name="model">report.analytic.account.close</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Sales Orders by product">
<form string="Expirated analytic accounts">
<field name="name" select="1"/>
<field name="partner_id" select="1"/>
<field name="quantity" select="1"/>
@ -23,12 +23,12 @@
</record>
<record model="ir.ui.view" id="view_analytic_account_tree">
<field name="name">report.analytic.account.tree</field>
<field name="model">report.analytic.account</field>
<record model="ir.ui.view" id="view_analytic_account_close_tree">
<field name="name">report.analytic.account.close.tree</field>
<field name="model">report.analytic.account.close</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Sales Orders by product">
<tree string="Expirated analytic accounts">
<field name="name"/>
<field name="partner_id"/>
<field name="quantity"/>
@ -40,8 +40,8 @@
</record>
<record model="ir.ui.view" id="view_analytic_account_graph">
<field name="name">report.analytic.account.graph</field>
<field name="model">report.analytic.account</field>
<field name="name">report.analytic.account.close.graph</field>
<field name="model">report.analytic.account.close</field>
<field name="type">graph</field>
<field name="arch" type="xml">
<graph string="Analytic accounts to close">
@ -53,8 +53,8 @@
</record>
<record model="ir.actions.act_window" id="action_analytic_account_tree">
<field name="name">report.analytic.account.tree</field>
<field name="res_model">report.analytic.account</field>
<field name="name">report.analytic.account.close.tree</field>
<field name="res_model">report.analytic.account.close</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
</record>
@ -62,6 +62,5 @@
action="action_analytic_account_tree"
id="menu_action_analytic_account_tree"/>
</data>
</terp>