[ADD]:Added SQL view for Analyatic Accounts.

bzr revid: apa@tinyerp.com-20100317113022-idk8rcm184pqcizq
This commit is contained in:
apa-tiny 2010-03-17 17:00:22 +05:30
parent b407c51517
commit 36ed0af606
4 changed files with 194 additions and 0 deletions

View File

@ -63,6 +63,7 @@
'account_installer.xml',
'report/account_invoice_report_view.xml',
'report/account_report_view.xml',
'report/account_analytic_report_view.xml',
],
'demo_xml': [
#'demo/price_accuracy00.yml',

View File

@ -36,6 +36,7 @@ import account_balance_landscape
import compare_account_balance
import account_invoice_report
import account_report
import account_analytic_report
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import tools
from osv import fields,osv
class analytic_report(osv.osv):
_name = "analytic.report"
_description = "Analytic Accounts Statistics"
_auto = False
_columns = {
'date_start': fields.date('Date Start', readonly=True),
'date_end': fields.date('Date End',readonly=True),
'name' : fields.char('Account', size=128, readonly=True),
'partner_id' : fields.many2one('res.partner', 'Associated Partner',readonly=True),
'journal_id' : fields.many2one('account.analytic.journal', 'Analytic Journal', readonly=True),
'parent_id': fields.many2one('account.analytic.account', 'Parent Analytic Account', readonly=True),
'user_id' : fields.many2one('res.users', 'Account Manager',readonly=True),
'product_id' : fields.many2one('product.product', 'Product',readonly=True),
'quantity': fields.float('Quantity',readonly=True),
'debit' : fields.float('Debit',readonly=True),
'credit' : fields.float('Credit',readonly=True),
'balance' : fields.float('Balance',readonly=True),
'year': fields.char('Year', size=4, readonly=True),
'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
'state': fields.selection([('draft','Draft'),
('open','Open'),
('pending','Pending'),
('cancelled', 'Cancelled'),
('close','Close'),
('template', 'Template')],
'State', readonly=True),
}
_order = 'date_start desc'
def init(self, cr):
tools.drop_view_if_exists(cr, 'analytic_report')
cr.execute("""
create or replace view analytic_report as (
select
min(s.id) as id,
to_char(s.create_date, 'YYYY') as year,
to_char(s.create_date, 'MM') as month,
l.journal_id,
l.product_id,
s.parent_id,
s.date_start,
s.date as date_end,
s.user_id,
s.name,
s.partner_id,
s.quantity,
s.debit,
s.credit,
s.balance,
count(*) as nbr,
s.state
from account_analytic_account s
left join account_analytic_line l on (s.id=l.account_id)
GROUP BY s.create_date,s.state,l.journal_id,s.name,
s.partner_id,s.date_start,s.date,s.user_id,s.quantity,
s.debit,s.credit,s.balance,s.parent_id,l.product_id
)
""")
analytic_report()

View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_analytic_report_tree" model="ir.ui.view">
<field name="name">analytic.report.tree</field>
<field name="model">analytic.report</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Analytic Accounts Statistics">
<field name="parent_id" invisible="1"/>
<field name="product_id" invisible="1"/>
<field name="name"/>
<field name="partner_id"/>
<field name="journal_id"/>
<field name="user_id"/>
<field name="date_start"/>
<field name="date_end"/>
<field name="quantity"/>
<field name="debit"/>
<field name="credit"/>
<field name="balance"/>
<field name="state"/>
<field name="month" invisible="1"/>
<field name="year" invisible="1"/>
</tree>
</field>
</record>
<record id="view_analytic_report_search" model="ir.ui.view">
<field name="name">analytic.report.search</field>
<field name="model">analytic.report</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Analytic Accounts">
<filter icon="terp-account"
string="This Year"
domain="[('year','=',time.strftime('%%Y'))]"
/>
<filter icon="terp-account"
string="This Month"
domain="[('month','=',time.strftime('%%m'))]"
/>
<separator orientation="vertical"/>
<filter string="Start" icon="terp-account" domain="[('date_start','=',time.strftime('%%Y/%%m/%%d'))]"/>
<filter string="End" icon="terp-account" domain="[('date_end','=',time.strftime('%%Y/%%m/%%d'))]"/>
<separator orientation="vertical"/>
<field name="name"/>
<field name="user_id" widget="selection">
<filter icon="terp-account"
string="My Accounts"
default="1"
domain="[('user_id','=',uid)]"/>
</field>
<field name="partner_id"/>
<newline/>
<group expand="1" string="Extended options..." colspan="10" col="12">
<filter icon="terp-account"
string="Draft"
domain="[('state','=','draft')]"/>
<filter icon="terp-account"
string="Open"
domain="[('state','=','open')]"/>
<filter icon="terp-account"
string="Pending"
domain="[('state','=','pending')]"/>
<filter icon="terp-account"
string="Close"
domain="[('state','=','close')]"/>
<filter icon="terp-account"
string="Template"
domain="[('state','=','template')]"/>
<separator orientation="vertical"/>
<field name="parent_id"/>
<field name="journal_id"/>
<field name="product_id"/>
<separator orientation="vertical"/>
<field name="date_start"/>
<field name="date_end"/>
</group>
<newline/>
<group expand="1" string="Group By..." colspan="10" col="12">
<filter string="Partner" icon="terp-account" context="{'group_by':'partner_id'}"/>
<filter string="User" icon="terp-account" context="{'group_by':'user_id'}" default="1"/>
<separator orientation="vertical"/>
<filter string="Product" icon="terp-account" context="{'group_by':'product_id'}"/>
<filter string="Journal" icon="terp-account" context="{'group_by':'journal_id'}"/>
<filter string="Parent Account" icon="terp-account" context="{'group_by':'parent_id'}"/>
<filter string="State" icon="terp-account" context="{'group_by':'state'}"/>
<separator orientation="vertical"/>
<filter string="Month" icon="terp-account" context="{'group_by':'month'}"/>
<filter string="Year" icon="terp-account" context="{'group_by':'year'}"/>
</group>
</search>
</field>
</record>
<record id="action_analytic_report_all" model="ir.actions.act_window">
<field name="name">Analytic Accounts</field>
<field name="res_model">analytic.report</field>
<field name="view_type">form</field>
<field name="view_mode">tree</field>
<field name="search_view_id" ref="view_analytic_report_search"/>
</record>
<menuitem action="action_analytic_report_all" id="menu_action_analytic_report_all" parent="account.menu_finance_reporting" sequence="0"/>
</data>
</openerp>