【发布时间】:2020-08-04 11:52:15
【问题描述】:
我正在尝试制作一个报告,其中用户从下拉列表中选择了一个产品,它显示了一个包含以下列的表格 创建日期、库存数量、进货和出货数量、供应商/客户和价格 因为它必须从不同的模型中获取每个字段,所以我不得不使用 sql 视图,但是当我加载 odoo 视图时它不显示任何字段,我确保视图的 sql 语句工作正常,并且检查数据库时,创建了视图,但视图上仍然没有显示任何内容
代码如下
from odoo import api, fields, models, tools, _
class ProductProfileReportView(models.Model):
_name = "product.profile.report"
_auto = False
action_type = fields.Char(string="Type")
create_date = fields.Date(string="Date")
invoice_id = fields.Many2one(comodel_name="custom.purchase", string="Invoice", required=False, )
qty = fields.Integer(string="Qty")
supplier_id = fields.Many2one(comodel_name="custom.supplier", string="Supplier", required=False, )
price = fields.Float(string="Price")
@api.model_cr
def init(self):
""" Event Question main report """
tools.drop_view_if_exists(self._cr, 'product_profile_report')
self._cr.execute(""" CREATE OR REPLACE VIEW product_profile_report AS (
select p.id as id,
'Purchase' as action_type,
pu.create_date as create_date,
pu.id as invoice_id,
pul.qty as qty,
s.id as supplier_id,
p.sell_price as price
from
custom_product p
inner join custom_purchase_line pul
on p.id = pul.product_id
inner join custom_purchase pu
on pul.purchase_id = pu.id
inner join custom_supplier s
on pu.supplier_id = s.id)""")
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="form_product_profile_report" model="ir.ui.view">
<field name="name">product.profile.report.form</field>
<field name="model">product.profile.report</field>
<field name="arch" type="xml">
<form string="">
<sheet>
<group>
<fields name="action_type"/>
<fields name="create_date"/>
<fields name="invoice_id"/>
<fields name="qty"/>
<fields name="supplier_id"/>
<fields name="price"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="action_product_profile_report" model="ir.actions.act_window">
<field name="name">product profile report</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.profile.report</field>
<field name="view_mode">form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create"></p>
</field>
</record>
<menuitem id="report_item" name="Reports" parent="custom_product_root"/>
<menuitem id="product_profile_report_submenu" name="Product Profile" parent="report_item"
action="action_product_profile_report"/>
</odoo>
【问题讨论】: