找不到模型odoo v8

时间:2018-10-06 06:53:16

标签: python xml odoo odoo-8

我想在采购申请模块中进行报告。因此,到目前为止,我已经完成了。 Purchase_requisition_report.py


nvm list

purchase_requisition_report_view.xml

from odoo import models, fields, api

class purchase_requisition_report(models.Model):
    _name = 'purchase.requisition.report'
    _description="Purchase Requisition Report"
    _column={
        'date': fields.datetime('Order Date', readonly=True, help="Date on which this document has been created"),
        'state': fields.selection([('draft', 'Request for Quotation'),
                                   ('confirmed', 'Waiting Supplier Ack'),
                                   ('approved', 'Approved'),
                                   ('done', 'Done'),
                                   ('cancel', 'Cancelled')], 'Purchase Requisition Status', readonly=True),
        'name': fields.char('Purchase Requisition No'),
        'product_id': fields.many2many('product.product','Product Name'),
        'supplier': fields.many2many('res.partner','Supplier Name'),
    }
    _order = 'date desc'
    def init(self, cr):
        tools.sql.drop_view_if_exists(cr, 'purchase_requisition_report')
        cr.execute("""
            create or replace view purchase_requisition_report as (
            SELECT 
              purchase_requisition.name, 
              product_product.name_template, 
              res_partner.display_name, 
              purchase_order.name, 
              purchase_requisition.state
            FROM 
              purchase_requisition_line inner join purchase_requisition on(purchase_requisition_line.requisition_id = purchase_requisition.id)
              inner join product_product on(purchase_requisition_line.product_id = product_product.id)
              inner join purchase_order on(purchase_order.requisition_id = purchase_requisition.id)
              inner join res_partner on(purchase_order.partner_id = res_partner.id);
            """)

openerp.py

    <?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

    <record id="view_purchase_requisition_report_tree" model="ir.ui.view">
        <field name="name">purchase.requisition.report.tree</field>
        <field name="model">purchase.requisition.report</field>
        <field name="arch" type="xml">
                <tree string="Purchase Requisition Report">
                    <field name="name"/>
                    <field name="product_id"/>
                    <field name="supplier"/>
                    <field name="state"/>
                </tree>
        </field>
    </record>

    <record id="view_purchase_requisition_report_search" model="ir.ui.view">
        <field name="name">purchase.requisition.report.search</field>
        <field name="model">purchase.requisition.report</field>
        <field name="arch" type="xml">
            <search string="Purchase Requisition Report">
                <filter string="Waiting" domain="[('state', '=' ,'confirm')]" help="Confirm Requisition"/>
                <filter string="Approved" domain="[('state','=','accepted')]" help="Approved Requisition"/>
                <filter string="Done" domain="[('state','=', 'done')]" help="Done Requisition"/>
                <group expand="0" string="Extended Filters...">
                    <field name="product_id"/>
                    <field name="user_id"/>
                    <field name="company_id" groups="base.group_multi_company"/>
                    <field name="date" string="Creation Date"/>
                    <field name="date_confirm"/>
                    <field name="date_valid"/>
                </group>
                <group expand="1" string="Group By">
                    <filter string="Purchase Requisition No" context="{'group_by':'name'}"/>
                    <filter string="Supplier" context="{'group_by':'supplier'}"/>
                    <filter string="Product" context="{'group_by':'product_id'}"/>
                    <filter string="Status" context="{'group_by':'state'}"/>
                    <filter string="Create Month" context="{'group_by':'create_date:month'}" help="Creation Date"/>
                </group>
            </search>
        </field>
    </record>
    <record id="action_purchase_requsition_report" model="ir.actions.act_window">
        <field name="name">Purchase Requisition</field>
        <field name="res_model">purchase.requisition.report</field>
        <field name="view_mode">tree</field>
        <field name="view_id" ref="view_purchase_requisition_report_tree"></field>
    </record>
    <menuitem id="base.next_id_73" name="Purchase" parent="base.menu_reporting" sequence="10"/>
    <menuitem action="action_purchase_requsition_report" id="menu_action_purchase_requsition_report" parent="base.next_id_73" sequence="10"/>

</data>
</openerp>

完成所有这些操作后,我得到以下错误

    {
    'name': 'Purchase Requisitions',
    'version': '0.1',
    'author': 'OpenERP SA',
    'category': 'Purchase Management',
    'website': 'https://www.odoo.com/page/purchase',
    'description': """
This module allows you to manage your Purchase Requisition.
===========================================================

When a purchase order is created, you now have the opportunity to save the
related requisition. This new object will regroup and will allow you to easily
keep track and order all your purchase orders.
""",
    'depends' : ['purchase'],
    'demo': ['purchase_requisition_demo.xml'],
    'data': ['views/purchase_requisition.xml',
              'security/purchase_tender.xml',
              'wizard/purchase_requisition_partner_view.xml',
              'wizard/bid_line_qty_view.xml',
              'purchase_requisition_data.xml',
              'purchase_requisition_view.xml',
              'purchase_requisition_report.xml',
              'report/purchase_requisition_report_view.xml',
              'purchase_requisition_workflow.xml',
              'security/ir.model.access.csv','purchase_requisition_sequence.xml',
              'views/report_purchaserequisition.xml',
    ],
    'auto_install': False,
    'test': [
        'test/purchase_requisition_users.yml',
        'test/purchase_requisition_demo.yml',
        'test/cancel_purchase_requisition.yml',
        'test/purchase_requisition.yml',
    ],
    'installable': True,
}

我无法找出错误出在哪里,请多多帮助。谢谢。 PS:我正在使用Odoo V.8

2 个答案:

答案 0 :(得分:0)

未导入的代码不会执行,因此这就是找不到它的可能性。

从模块的__init__.py文件中导入它:

from . import purchase_requisition_report

答案 1 :(得分:0)

您的日志应充满导入错误。如果您使用的是Odoo v8,则应使用openerp而不是odoo,因为那时候odoo软件包不存在,因此您需要这样做:

from openerp import models, fields, api, tools

由于您没有包含工具,因此我在imports中包含了工具。同样,如果您将创建一个SQL View用作模型表,则应指示ORM不要尝试为模型添加创建表:

_auto = False

之后,如果在Odoo服务器启动时日志中没有看到其他任何错误,则应该没问题