Skip to content

Commit

Permalink
[IMP] Add section_id in the invoice analysis report.
Browse files Browse the repository at this point in the history
bzr revid: vba@tinyerp.com-20121121101909-hez6fxcqcyn3njy8
  • Loading branch information
vba-odoo committed Nov 21, 2012
1 parent 4cbd5c5 commit d17568d
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 19 deletions.
49 changes: 34 additions & 15 deletions addons/account/report/account_invoice_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,13 @@ def _compute_amounts_in_user_currency(self, cr, uid, ids, field_names, args, con
'user_currency_residual': fields.function(_compute_amounts_in_user_currency, string="Total Residual", type='float', digits_compute=dp.get_precision('Account'), multi="_compute_amounts"),
'delay_to_pay': fields.float('Avg. Delay To Pay', readonly=True, group_operator="avg"),
'due_delay': fields.float('Avg. Due Delay', readonly=True, group_operator="avg"),
'section_id': fields.many2one('crm.case.section', 'Sales Team'),
}
_order = 'date desc'
def init(self, cr):
tools.drop_view_if_exists(cr, 'account_invoice_report')
cr.execute("""
create or replace view account_invoice_report as (
select min(ail.id) as id,


def _select(self):
select_str = """
SELECT min(ail.id) as id,
ai.date_invoice as date,
to_char(ai.date_invoice, 'YYYY') as year,
to_char(ai.date_invoice, 'MM') as month,
Expand All @@ -125,7 +124,6 @@ def init(self, cr):
ai.journal_id as journal_id,
ai.fiscal_position as fiscal_position,
ai.user_id as user_id,
ai.section_id as section_id,
ai.company_id as company_id,
count(ail.*) as nbr,
ai.type as type,
Expand Down Expand Up @@ -185,15 +183,30 @@ def init(self, cr):
where a.id=ai.id)
ELSE 1
END) / cr.rate as residual
from account_invoice_line as ail
"""
return select_str

def _where(self):
where_str = """
WHERE cr.id in (select id from res_currency_rate cr2 where (cr2.currency_id = ai.currency_id)
and ((ai.date_invoice is not null and cr.name <= ai.date_invoice) or (ai.date_invoice is null and cr.name <= NOW())) order by name desc limit 1)
"""
return where_str

def _from(self):
from_str = """
FROM account_invoice_line as ail
left join account_invoice as ai ON (ai.id=ail.invoice_id)
left join product_product pr on (pr.id=ail.product_id)
left join product_template pt on (pt.id=pr.product_tmpl_id)
left join product_uom u on (u.id=ail.uos_id),
res_currency_rate cr
where cr.id in (select id from res_currency_rate cr2 where (cr2.currency_id = ai.currency_id)
and ((ai.date_invoice is not null and cr.name <= ai.date_invoice) or (ai.date_invoice is null and cr.name <= NOW())) order by name desc limit 1)
group by ail.product_id,
"""
return from_str

def _group_by(self):
group_by_str = """
GROUP BY ail.product_id,
ai.date_invoice,
ai.id,
cr.rate,
Expand All @@ -219,10 +232,16 @@ def init(self, cr):
ai.residual,
ai.amount_total,
u.uom_type,
u.category_id,
ai.section_id
)
""")
u.category_id
"""
return group_by_str

def init(self, cr):
# self._table = account_invoice_report
tools.drop_view_if_exists(cr, self._table)
cr.execute("CREATE or REPLACE VIEW %s as (%s %s %s %s)" % (
self._table,
self._select(), self._from(), self._where(), self._group_by()))

account_invoice_report()

Expand Down
3 changes: 0 additions & 3 deletions addons/account/report/account_invoice_report_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<field name="account_line_id" invisible="1"/>
<field name="nbr" sum="# of Lines"/>
<field name="product_qty" sum="Qty"/>
<field name="section_id"/>
<!-- <field name="reconciled" sum="# Reconciled"/> -->
<field name="user_currency_price_total" sum="Total Without Tax"/>
<field name="user_currency_residual" sum="Total Residual" invisible="context.get('residual_invisible',False)"/>
Expand Down Expand Up @@ -66,7 +65,6 @@
<filter icon="terp-dolar_ok!" string="Refund" domain="['|', ('type','=','out_refund'),('type','=','in_refund')]" help="Customer And Supplier Refunds"/>
<field name="partner_id"/>
<field name="user_id" />
<field name="section_id" />
<field name="categ_id" filter_domain="[('categ_id', 'child_of', self)]"/>
<group expand="1" string="Group By...">
<filter string="Partner" name="partner" icon="terp-partner" context="{'group_by':'partner_id','residual_visible':True}"/>
Expand All @@ -83,7 +81,6 @@
<filter string="Day" name="day" icon="terp-go-today" context="{'group_by':'day'}" help="Group by Invoice Date"/>
<filter string="Month" name="month" icon="terp-go-month" context="{'group_by':'month'}" help="Group by month of Invoice Date"/>
<filter string="Year" name="group_year" icon="terp-go-year" context="{'group_by':'year'}" help="Group by year of Invoice Date"/>
<filter string="Sales Team" name='section_id' icon="terp-personal" context="{'group_by':'section_id'}"/>
</group>
</search>
</field>
Expand Down
1 change: 1 addition & 0 deletions addons/sale_crm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@

import wizard
import sale_crm
import report

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
3 changes: 2 additions & 1 deletion addons/sale_crm/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
'sale_crm_view.xml',
'process/sale_crm_process.xml',
'security/sale_crm_security.xml',
'security/ir.model.access.csv'
'security/ir.model.access.csv',
'report/sale_crm_account_invoice_report_view.xml',
],
'demo': [],
'test': ['test/sale_crm.yml'],
Expand Down
25 changes: 25 additions & 0 deletions addons/sale_crm/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- 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 sales_crm_account_invoice_report

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

20 changes: 20 additions & 0 deletions addons/sale_crm/report/sale_crm_account_invoice_report_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<!-- Update account invoice !-->
<record model="ir.ui.view" id="account_invoice_report_tree">
<field name="name">account.invoice.report.tree</field>
<field name="model">account.invoice.report</field>
<field name="inherit_id" ref="account.view_account_invoice_report_tree"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='date']" position="after">
<field name="section_id"/>
</xpath>
</data>
</field>
</record>

</data>
</openerp>
35 changes: 35 additions & 0 deletions addons/sale_crm/report/sales_crm_account_invoice_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- 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/>.
#
##############################################################################
from osv import fields,osv

class account_invoice_report(osv.osv):
_inherit = 'account.invoice.report'
_columns = {
'section_id': fields.many2one('crm.case.section', 'Sales Team'),
}

def _select(self):
return super(account_invoice_report, self)._select() + ", ai.section_id as section_id"

def _group_by(self):
return super(account_invoice_report, self)._group_by() + ", ai.section_id"

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

0 comments on commit d17568d

Please sign in to comment.