Hello everybody!!!
I want toadd a colum in the dashboard of sale.
I have tried this but it doesnt work :/
class sale_report(osv.osv):
_inherit = 'sale.report'
_columns = {
'product_commission': fields.float('# Commission Price', readonly=True),
}
def _select(self):
select_str = """
WITH currency_rate (currency_id, rate, date_start, date_end) AS (
SELECT r.currency_id, r.rate, r.name AS date_start,
(SELECT name FROM res_currency_rate r2
WHERE r2.name > r.name AND
r2.currency_id = r.currency_id
ORDER BY r2.name ASC
LIMIT 1) AS date_end
FROM res_currency_rate r
)
SELECT min(l.id) as id,
l.product_id as product_id,
t.uom_id as product_uom,
sum(l.product_uom_qty * l.price_unit / cr.rate * (100.0-l.discount) / 100.0) as product_commission,
sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty,
sum(l.product_uom_qty * l.price_unit / cr.rate * (100.0-l.discount) / 100.0) as price_total,
count(*) as nbr,
s.date_order as date,
s.date_confirm as date_confirm,
s.partner_id as partner_id,
s.user_id as user_id,
s.company_id as company_id,
extract(epoch from avg(date_trunc('day',s.date_confirm)-date_trunc('day',s.create_date)))/(24*60*60)::decimal(16,2) as delay,
l.state,
t.categ_id as categ_id,
s.pricelist_id as pricelist_id,
s.project_id as analytic_account_id,
s.section_id as section_id
"""
return select_str
def _from(self):
from_str = """
sale_order_line l
join sale_order s on (l.order_id=s.id)
left join product_product p on (l.product_id=p.id)
left join product_template t on (p.product_tmpl_id=t.id)
left join product_uom u on (u.id=l.product_uom)
left join product_uom u2 on (u2.id=t.uom_id)
left join product_pricelist pp on (s.pricelist_id = pp.id)
join currency_rate cr on (cr.currency_id = pp.currency_id and
cr.date_start <= coalesce(s.date_order, now()) and
(cr.date_end is null or cr.date_end > coalesce(s.date_order, now())))
"""
return from_str
def _group_by(self):
group_by_str = """
GROUP BY l.product_id,
l.order_id,
t.uom_id,
t.categ_id,
s.date_order,
s.date_confirm,
s.partner_id,
s.user_id,
s.company_id,
l.state,
s.pricelist_id,
s.project_id,
s.section_id
"""
return group_by_str
def init(self, cr):
# self._table = sale_report
tools.drop_view_if_exists(cr, self._table)
cr.execute("""CREATE or REPLACE VIEW %s as (
%s
FROM ( %s )
%s
)""" % (self._table, self._select(), self._from(), self._group_by()))
sale_report()
Can anyone help me please.
I got this error :
2017-03-25 22:14:24,275 19102 ERROR company_test openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
File "/opt/openerp/openerp/http.py", line 544, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/openerp/openerp/http.py", line 581, in dispatch
result = self._call_function(**self.params)
File "/opt/openerp/openerp/http.py", line 317, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/openerp/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/openerp/openerp/http.py", line 314, in checked_call
return self.endpoint(*a, **kw)
File "/opt/openerp/openerp/http.py", line 810, in __call__
return self.method(*args, **kw)
File "/opt/openerp/openerp/http.py", line 410, in response_wrap
response = f(*args, **kw)
File "/opt/openerp/addons/web/controllers/main.py", line 944, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/opt/openerp/addons/web/controllers/main.py", line 936, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/opt/openerp/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/openerp/openerp/models.py", line 2148, in read_group
cr.execute(query, where_clause_params)
File "/opt/openerp/openerp/sql_db.py", line 158, in wrapper
return f(self, *args, **kwargs)
File "/opt/openerp/openerp/sql_db.py", line 234, in execute
res = self._obj.execute(query, params)
ProgrammingError: column sale_report.product_commission does not exist LINE 2: ...m("sale_report"."price_total") AS price_total,sum("sale_repo...