1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from openerp.osv import fields,osv
23 from openerp import tools
24 from openerp.addons.decimal_precision import decimal_precision as dp
27 class report_analytic_account_close(osv.osv):
28 _name = "report.analytic.account.close"
29 _description = "Analytic account to close"
32 'name': fields.many2one('account.analytic.account', 'Analytic account', readonly=True),
33 'state': fields.char('Status', size=32, readonly=True),
34 'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
35 'quantity': fields.float('Quantity', readonly=True),
36 'quantity_max': fields.float('Max. Quantity', readonly=True),
37 'balance': fields.float('Balance', readonly=True),
38 'date_deadline': fields.date('Deadline', readonly=True),
41 tools.drop_view_if_exists(cr, 'report_analytic_account_close')
43 create or replace view report_analytic_account_close as (
48 sum(l.unit_amount) as quantity,
49 sum(l.amount) as balance,
50 a.partner_id as partner_id,
51 a.quantity_max as quantity_max,
52 a.date as date_deadline
54 account_analytic_line l
56 account_analytic_account a on (l.account_id=a.id)
58 a.id,a.state, a.quantity_max,a.date,a.partner_id
60 (a.quantity_max>0 and (sum(l.unit_amount)>=a.quantity_max)) or
61 a.date <= current_date
64 class report_account_analytic_line_to_invoice(osv.osv):
65 _name = "report.account.analytic.line.to.invoice"
66 _description = "Analytic lines to invoice report"
69 'name': fields.char('Year',size=64,required=False, readonly=True),
70 'product_id':fields.many2one('product.product', 'Product', readonly=True),
71 'account_id':fields.many2one('account.analytic.account', 'Analytic account', readonly=True),
72 'product_uom_id':fields.many2one('product.uom', 'Unit of Measure', readonly=True),
73 'unit_amount': fields.float('Units', readonly=True),
74 'sale_price': fields.float('Sale price', readonly=True, digits_compute=dp.get_precision('Product Price')),
75 'amount': fields.float('Amount', readonly=True, digits_compute=dp.get_precision('Account')),
76 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
77 ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
79 _order = 'name desc, product_id asc, account_id asc'
82 tools.drop_view_if_exists(cr, 'report_account_analytic_line_to_invoice')
84 CREATE OR REPLACE VIEW report_account_analytic_line_to_invoice AS (
86 DISTINCT(to_char(l.date,'MM')) as month,
87 to_char(l.date, 'YYYY') as name,
91 SUM(l.amount) AS amount,
92 SUM(l.unit_amount*t.list_price) AS sale_price,
93 SUM(l.unit_amount) AS unit_amount,
96 account_analytic_line l
98 product_product p on (l.product_id=p.id)
100 product_template t on (p.product_tmpl_id=t.id)
102 (invoice_id IS NULL) and (to_invoice IS NOT NULL)
104 to_char(l.date, 'YYYY'), to_char(l.date,'MM'), product_id, product_uom_id, account_id
108 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: