I have create a list view with the help of psql query with _auto = False
. So there is not model registered against this. Now i want to customize this click event on the records that whenever a user click on any records i want to pass an order_id and then redirect user to that particular order detail screen.
Edit
View
<odoo>
<data>
<record id="amgl_dashboard_tree" model="ir.ui.view">
<field name="name">Dashboard</field>
<field name="model">amgl.dashboard</field>
<field name="arch" type="xml">
<tree default_order="state desc" decoration-bf ="state in ('expecting','pending','completed')" decoration-info="state=='expecting'" decoration-danger="state=='pending'" decoration-succes="state=='completed'" string="Dashboard" create="false" edit="false">
<field name="order_id" invisible="1"/>
<button name="view_record" type="object" string="View Record" custom="click" class="oe_highlight"/>
<field name="first_name"/>
<field name="last_name"/>
<field name="account_number"/>
<field name="product"/>
<field name="quantity"/>
<field name="total_weight"/>
<field name="state"/>
</tree>
</field>
</record>
</data>
</odoo>
.Py
class Dashboard(models.Model):
_name = 'amgl.dashboard'
_auto = False
@api.multi
def view_record(self):
print self
@api.model_cr
def init(self):
tools.drop_view_if_exists(self._cr, 'dashboard')
self._cr.execute("""
CREATE or REPLACE VIEW amgl_dashboard AS (
SELECT
row_number() OVER () AS id,
c.name AS first_name,
c.last_name AS last_name,
c.account_type AS account_type,
c.account_number AS account_number,
(select name from amgl_products where id = ol.products) AS product,
ol.quantity AS quantity,
(CASE
WHEN (select weight_unit from amgl_products where id = ol.products) = 'oz'
THEN
(select weight_per_piece from public.amgl_products where id = ol.products) * ol.quantity
WHEN (select weight_unit from amgl_products where id = ol.products) = 'gram'
THEN
((select weight_per_piece from public.amgl_products where id = ol.products) / 28.34952) * ol.quantity
WHEN (select weight_unit from amgl_products where id = ol.products) = 'pounds'
THEN
((select weight_per_piece from amgl_products where id = ol.products) * 16) * ol.quantity
WHEN (select weight_unit from amgl_products where id = ol.products) = 'kg'
THEN
((select weight_per_piece from amgl_products where id = ol.products) / 0.02834952) * ol.quantity
ELSE 0.0
END) AS total_weight,
o.state AS state,
o.id AS order_id
FROM amgl_order AS o
INNER JOIN amgl_customer AS c ON c.id = o.customer_id
INNER JOIN amgl_order_line AS ol ON ol.order_id = o.id
)""")
name = fields.Char()
first_name = fields.Char(string="First Name")
last_name = fields.Char(string="Last Name")
account_type = fields.Char(string="Account Type")
account_number = fields.Char(string="Account Number")
product = fields.Char(string="Product")
quantity = fields.Float(string="Quantity")
total_weight = fields.Float(string="Total Weight")
state = fields.Selection([('expecting', 'Expecting'), ('pending', 'Pending'),
('completed', 'Completed'), ('waiting', 'Waiting For Approval')],
'Status', default='expecting')
order_id = fields.Integer(string="Order Id")
Action
<record id="amgl.dashboard_action_window" model="ir.actions.act_window">
<field name="name">Dashboard</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">amgl.dashboard</field>
<field name="view_mode">tree</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
<!-- Add Text Here -->
</p><p>
<!-- More details about what a user can do with this object will be OK -->
</p>
</field>
</record>
Debugger
Self._context
Self
_auto=False
doesn't create table. – Ancient