Skip to Content
Menu
This question has been flagged
1 Reply
9033 Views

I created on module called purchase_analysis.py


from odoo import models, fields, api, tools

class purchase_analysis(models.Model):
_name = 'purchase_analysis.purchase_analysis'

_auto = False
Purchase_Request_Product = fields.Char('Request Product')
Purchase_Request_SourceDocuments = fields.Char('Purchase Request SourceDocuments')
Purchase_Request_Date = fields.Date('Purchase Request Date')
Purchase_Request_Desc = fields.Char('Purchase Request Desc')
Purchase_Request_Product_Qty = fields.Char('Purchase Request Product Qty')
Purchase_Order_Line_Prices = fields.Char('Purchase Order Line Prices')
Purchase_Order_Line_Totals_Prices = fields.Char('Purchase Order Line Totals Prices')
Purchase_Order_Number = fields.Char('Purchase Order_Number')
Purchase_Order_Amount = fields.Char('Purchase Order_Amount')
Purchase_Order_Date = fields.Date('Purchase Order Date')
Purchase_Order_Vendors = fields.Char('Purchase Order Vendors')
Purchase_Order_Status = fields.Char('Purchase Order Status')
Purchase_Order_invoice_status = fields.Char('Purchase Order Invoice Status')
Purchase_Order_Line_Qty = fields.Char('Purchase Order Line Qty')
Purchase_Order_Line_Qty_received_Totals = fields.Char('Purchase Order Line Qty received Totals')
Purchase_Order_Line_Qty_Invoice_Totals = fields.Char('Purchase Order Line Qty Invoice Totals')
Expected_Supply_Date = fields.Char('Expected Supply Date')



@api.model_cr # cr
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self._cr.execute("""create or replace view purchase_analysis as
(SELECT purchase_request_line.name AS Purchase_Request_Product,
purchase_request.origin AS Purchase_Request_SourceDocuments,
purchase_request.date_start AS Purchase_Request_Date,
purchase_request.description AS Purchase_Request_Desc,
purchase_request_line.product_qty AS Purchase_Request_Product_Qty,
purchase_order_line.price_unit AS Purchase_Order_Line_Prices,
purchase_order_line.price_total AS Purchase_Order_Line_Totals_Prices,
purchase_order.name AS Purchase_Order_Number,
purchase_order.amount_total As Purchase_Order_Amount,
purchase_order.date_order AS Purchase_Order_Date,
res_partner.name AS Purchase_Order_Vendors,
purchase_order.state AS Purchase_Order_Status,
purchase_order.invoice_status AS Purchase_Order_invoice_status,
purchase_order_line.product_qty AS Purchase_Order_Line_Qty,
purchase_order_line.qty_received AS Purchase_Order_Line_Qty_received_Totals,
purchase_order_line.qty_invoiced AS Purchase_Order_Line_Qty_Invoice_Totals,
purchase_order.date_planned AS Expected_Supply_Date
FROM
public.purchase_request,
public.purchase_request_line,
public.purchase_order,
public.purchase_order_line,
public.purchase_request_purchase_order_line_rel,
public.res_partner
WHERE
purchase_request_line.request_id = purchase_request.id AND
purchase_order.partner_id = res_partner.id AND
purchase_order_line.order_id = purchase_order.id AND
purchase_request_purchase_order_line_rel.purchase_request_line_id = purchase_request_line.id AND
purchase_request_purchase_order_line_rel.purchase_order_line_id = purchase_order_line.id)""")

view.xml

<odoo>
<data>

<record id="Purchase_Analysis_tree_view1" model="ir.ui.view">
<field name="name">view.purchase_analysis.tree</field>
<field name="model">purchase_analysis.purchase_analysis</field>
<field name="arch" type="xml">
<tree>

<field name="Purchase_Request_Product"/>
<field name="Purchase_Request_SourceDocuments"/>
<field name="Purchase_Request_Date"/>
<field name="Purchase_Request_Desc"/>
<field name="Purchase_Request_Product_Qty"/>
<field name="Purchase_Order_Line_Totals_Prices"/>
<field name="Purchase_Order_Number"/>
<field name="Purchase_Order_Amount"/>
<field name="Purchase_Order_Vendors"/>
<field name="Purchase_Order_Status"/>
<field name="Purchase_Order_invoice_status"/>
<field name="Purchase_Order_Line_Qty"/>
<field name="Purchase_Order_Line_Qty_received_Totals"/>
<field name="Purchase_Order_Line_Qty_Invoice_Totals"/>
<field name="Expected_Supply_Date"/>
</tree>
</field>
</record>

<record id="Purchase_Analysis_tree_view" model="ir.actions.act_window">
<field name="name">Purchase Anaylsis</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase_analysis.purchase_analysis</field>
<field name="view_type">form</field>
<field name="view_mode">tree</field>
</record>
<menuitem
name="Purchase Analysis"
action="Purchase_Analysis_tree_view"
id="menu_purchase_request_line"
parent="purchase.menu_procurement_management"
/>


</data>
</odoo>


am getting am error when i am run it saying these 


 File "C:\Program Files (x86)\Odoo 11.0e\server\odoo\sql_db.py", line 232, in execute
    res = self._obj.execute(query, params)
psycopg2.ProgrammingError: relation "purchase_analysis_purchase_analysis" does not exist
LINE 1: ...ECT "purchase_analysis_purchase_analysis".id FROM "purchase_...

the purpose from these module to read from query to list view direct may some one guide me  

Avatar
Discard
Best Answer

Try this:

Hope it helps you!


@api.model_cr # cr
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self._cr.execute("""CREATE OR REPLACE VIEW %s AS
(SELECT purchase_request_line.name AS Purchase_Request_Product,
purchase_request.origin AS Purchase_Request_SourceDocuments,
purchase_request.date_start AS Purchase_Request_Date,
purchase_request.description AS Purchase_Request_Desc,
purchase_request_line.product_qty AS Purchase_Request_Product_Qty,
purchase_order_line.price_unit AS Purchase_Order_Line_Prices,
purchase_order_line.price_total AS Purchase_Order_Line_Totals_Prices,
purchase_order.name AS Purchase_Order_Number,
purchase_order.amount_total As Purchase_Order_Amount,
purchase_order.date_order AS Purchase_Order_Date,
res_partner.name AS Purchase_Order_Vendors,
purchase_order.state AS Purchase_Order_Status,
purchase_order.invoice_status AS Purchase_Order_invoice_status,
purchase_order_line.product_qty AS Purchase_Order_Line_Qty,
purchase_order_line.qty_received AS Purchase_Order_Line_Qty_received_Totals,
purchase_order_line.qty_invoiced AS Purchase_Order_Line_Qty_Invoice_Totals,
purchase_order.date_planned AS Expected_Supply_Date
FROM
public.purchase_request,
public.purchase_request_line,
public.purchase_order,
public.purchase_order_line,
public.purchase_request_purchase_order_line_rel,
public.res_partner
WHERE
purchase_request_line.request_id = purchase_request.id AND
purchase_order.partner_id = res_partner.id AND
purchase_order_line.order_id = purchase_order.id AND
purchase_request_purchase_order_line_rel.purchase_request_line_id = purchase_request_line.id AND
purchase_request_purchase_order_line_rel.purchase_order_line_id = purchase_order_line.id)"""% self._table)
Avatar
Discard
Related Posts Replies Views Activity
2
Jul 24
940
1
Jun 24
3561
1
Oct 23
8589
1
Oct 23
97
1
Aug 23
2192