1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# sale_margin module for OpenERP, add margin in sale order and invoice
5
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6
# Copyright (C) 2009 EVERLIBRE (<http://www.Everlibre.fr>) Éric VERNICHON
7
# Copyright (C) 2009 SYLEAM (<http://www.Syleam.fr>) Sebastien LANGE
9
# This file is a part of sale_margin
11
# sale_margin is free software: you can redistribute it and/or modify
12
# it under the terms of the GNU General Public License as published by
13
# the Free Software Foundation, either version 3 of the License, or
14
# (at your option) any later version.
16
# sale_margin is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
21
# You should have received a copy of the GNU General Public License
22
# along with this program. If not, see <http://www.gnu.org/licenses/>.
24
##############################################################################
26
from osv import fields,osv
28
from tools import config
33
class report_account_invoice_product(osv.osv):
34
_name = 'report.account.invoice.product'
37
'name': fields.date('Month', readonly=True),
38
'type': fields.selection([
39
('out_invoice','Customer Invoice'),
40
('in_invoice','Supplier Invoice'),
41
('out_refund','Customer Refund'),
42
('in_refund','Supplier Refund'),
43
],'Type', readonly=True),
44
'state': fields.selection([
46
('proforma','Pro-forma'),
50
],'State', readonly=True),
51
'product_id': fields.many2one('product.product', 'Product', readonly=True),
52
'amount': fields.float('Amount', readonly=True),
53
'cost_price': fields.float('Cost Price', readonly=True),
54
'margin': fields.float('Margin', readonly=True),
55
'quantity': fields.float('Quantity', readonly=True),
60
create or replace view report_account_invoice_product as (
63
to_char(i.date_invoice, 'YYYY-MM-01') as name,
67
sum(l.quantity * l.price_unit * (1.0 - l.discount/100.0)) as amount,
68
sum(l.quantity * l.cost_price) as cost_price,
69
sum((l.quantity * l.price_unit * (1.0 - l.discount/100.0) - (l.quantity * l.cost_price))) as margin,
70
sum(l.quantity) as quantity
71
from account_invoice i
72
left join account_invoice_line l on (i.id = l.invoice_id)
73
group by l.product_id, to_char(i.date_invoice, 'YYYY-MM-01'), i.type, i.state
76
report_account_invoice_product()
78
class report_account_invoice_category(osv.osv):
79
_name = 'report.account.invoice.category'
82
'name': fields.date('Month', readonly=True),
83
'type': fields.selection([
84
('out_invoice','Customer Invoice'),
85
('in_invoice','Supplier Invoice'),
86
('out_refund','Customer Refund'),
87
('in_refund','Supplier Refund'),
88
],'Type', readonly=True),
89
'state': fields.selection([
91
('proforma','Pro-forma'),
95
],'State', readonly=True),
96
'categ_id': fields.many2one('product.category', 'Categories', readonly=True),
97
'amount': fields.float('Amount', readonly=True),
98
'cost_price': fields.float('Cost Price', readonly=True),
99
'margin': fields.float('Margin', readonly=True),
100
'quantity': fields.float('Quantity', readonly=True),
105
create or replace view report_account_invoice_category as (
108
to_char(i.date_invoice, 'YYYY-MM-01') as name,
112
sum(l.quantity * l.price_unit * (1.0 - l.discount/100.0)) as amount,
113
sum(l.quantity * l.cost_price) as cost_price,
114
sum((l.quantity * l.price_unit * (1.0 - l.discount/100.0) - (l.quantity * l.cost_price))) as margin,
115
sum(l.quantity) as quantity
116
from account_invoice i
117
left join account_invoice_line l on (i.id = l.invoice_id)
118
left join product_product p on (p.id = l.product_id)
119
left join product_template t on (t.id = p.product_tmpl_id)
120
group by t.categ_id, to_char(i.date_invoice, 'YYYY-MM-01'), i.type, i.state
123
report_account_invoice_category()
125
class report_account_invoice_partner(osv.osv):
126
_name = 'report.account.invoice.partner'
129
'name': fields.date('Month', readonly=True),
130
'type': fields.selection([
131
('out_invoice','Customer Invoice'),
132
('in_invoice','Supplier Invoice'),
133
('out_refund','Customer Refund'),
134
('in_refund','Supplier Refund'),
135
],'Type', readonly=True),
136
'state': fields.selection([
138
('proforma','Pro-forma'),
141
('cancel','Canceled')
142
],'State', readonly=True),
143
'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
144
'amount': fields.float('Amount', readonly=True),
145
'cost_price': fields.float('Cost Price', readonly=True),
146
'margin': fields.float('Margin', readonly=True),
147
'quantity': fields.float('Quantity', readonly=True),
152
create or replace view report_account_invoice_partner as (
155
to_char(i.date_invoice, 'YYYY-MM-01') as name,
159
sum(l.quantity * l.price_unit * (1.0 - l.discount/100.0)) as amount,
160
sum(l.quantity * l.cost_price) as cost_price,
161
sum((l.quantity * l.price_unit * (1.0 - l.discount/100.0) - (l.quantity * l.cost_price))) as margin,
162
sum(l.quantity) as quantity
163
from account_invoice i
164
left join account_invoice_line l on (i.id = l.invoice_id)
165
group by i.partner_id, to_char(i.date_invoice, 'YYYY-MM-01'), i.type, i.state
168
report_account_invoice_partner()
170
class report_account_invoice_partner_product(osv.osv):
171
_name = 'report.account.invoice.partner.product'
174
'name': fields.date('Month', readonly=True),
175
'type': fields.selection([
176
('out_invoice','Customer Invoice'),
177
('in_invoice','Supplier Invoice'),
178
('out_refund','Customer Refund'),
179
('in_refund','Supplier Refund'),
180
],'Type', readonly=True),
181
'state': fields.selection([
183
('proforma','Pro-forma'),
186
('cancel','Canceled')
187
],'State', readonly=True),
188
'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
189
'product_id': fields.many2one('product.product', 'Product', readonly=True),
190
'amount': fields.float('Amount', readonly=True),
191
'cost_price': fields.float('Cost Price', readonly=True),
192
'margin': fields.float('Margin', readonly=True),
193
'quantity': fields.float('Quantity', readonly=True),
198
create or replace view report_account_invoice_partner_product as (
201
to_char(i.date_invoice, 'YYYY-MM-01') as name,
206
sum(l.quantity * l.price_unit * (1.0 - l.discount/100.0)) as amount,
207
sum(l.quantity * l.cost_price) as cost_price,
208
sum((l.quantity * l.price_unit * (1.0 - l.discount/100.0) - (l.quantity * l.cost_price))) as margin,
209
sum(l.quantity) as quantity
210
from account_invoice i
211
left join account_invoice_line l on (i.id = l.invoice_id)
212
group by i.partner_id, l.product_id, to_char(i.date_invoice, 'YYYY-MM-01'), i.type, i.state
215
report_account_invoice_partner_product()
218
class report_account_invoice(osv.osv):
219
_name = 'report.account.invoice'
222
'name': fields.date('Month', readonly=True),
223
'type': fields.selection([
224
('out_invoice','Customer Invoice'),
225
('in_invoice','Supplier Invoice'),
226
('out_refund','Customer Refund'),
227
('in_refund','Supplier Refund'),
228
],'Type', readonly=True),
229
'state': fields.selection([
231
('proforma','Pro-forma'),
234
('cancel','Canceled')
235
],'State', readonly=True),
236
'amount': fields.float('Amount', readonly=True),
237
'cost_price': fields.float('Cost Price', readonly=True),
238
'margin': fields.float('Margin', readonly=True),
239
'quantity': fields.float('Quantity', readonly=True),
244
create or replace view report_account_invoice as (
247
to_char(i.date_invoice, 'YYYY-MM-01') as name,
250
sum(l.quantity * l.price_unit * (1.0 - l.discount/100.0)) as amount,
251
sum(l.quantity * l.cost_price) as cost_price,
252
sum((l.quantity * l.price_unit * (1.0 - l.discount/100.0) - (l.quantity * l.cost_price))) as margin,
253
sum(l.quantity) as quantity
254
from account_invoice i
255
left join account_invoice_line l on (i.id = l.invoice_id)
256
group by to_char(i.date_invoice, 'YYYY-MM-01'), i.type, i.state
259
report_account_invoice()
260
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: