在树视图中显示所有One2Many模型字段 - Odoo 11.0

时间:2018-02-11 10:23:24

标签: python-3.x odoo odoo-10 odoo-11

我有两种模式:

class Requisition(models.Model):
    '''
    This module is responsible for all of the requisition related operations.
    '''

    _name = 'mir.requisition'
    _description = 'Mir Requisition'

    name = fields.Char('Requisition Name', required=True)
    company_id = fields.Many2one('res.company', string='Company')
    requisition_line_ids = fields.One2many('mir.requisition.line', 'requisition_id', string='Requisition Line')


class RequisitionLine(models.Model):
    '''
        This module is responsible for all of the requisition line item related operations.
    '''
    _name = 'mir.requisition.line'
    _description = 'Mir Requisition Line'

    product_id = fields.Many2one(
        'product.product', 'Product', required=True)
    product_qty = fields.Float(
        'Quantity',
        digits=dp.get_precision('Product Unit of Measure'), default=0, required=True)
    product_uom_id = fields.Many2one(
        'product.uom', 'Unit of Measure',
        oldname='product_uom', required=True)
    delivery_date = fields.Date(string='Delivery Date', required=True)
    delivery_location = fields.Many2one('stock.location', 'Warehouse Location', required=True)
    requisition_id = fields.Many2one('mir.requisition', string='Mir Requisition Reference', index=True, ondelete='cascade')
    status = fields.Selection([
        ('draft', 'Draft'),
        ('in_progress', 'In Progress'),
        ('approved', 'Approved'),
        ('cancel', 'Cancel'),
    ], 'draft')

    @api.onchange('product_id')
    def _product_onchange(self):
        product = self.product_id
        self.product_uom_id = self.product_id.uom_id.id
        return {'domain': {'product_uom': [('category_id', '=', product.uom_id.category_id.id)]}}

并且查看是:

 <!--Requisition Tree View-->
    <record id="mir_requisition_tree" model="ir.ui.view">
        <field name="name">Requisition</field>
        <field name="model">mir.requisition</field>
        <field name="arch" type="xml">
            <tree string="Requisition">
                <field name="name"/>
                <field name="company_id"/>
                <field name="create_uid" string="Created By"/>
                <field name="create_date" string="Created Date"/>
            </tree>
        </field>
    </record>

目前,此视图显示父模型mir.requisition的数据。但我想在一个视图中显示两个模型数据。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

您应该查看 invoice_form definition,它适用于&#39; account.invoice&#39;和&#39; account.invoice.line&#39;楷模。它是这样的:

<!--Requisition Tree View-->
<record id="mir_requisition_tree" model="ir.ui.view">
    <field name="name">Requisition</field>
    <field name="model">mir.requisition</field>
    <field name="arch" type="xml">
        <form string="Requisition">
            <field name="name"/>
            <field name="company_id"/>
            <field name="create_uid" string="Created By"/>
            <field name="create_date" string="Created Date"/>
            <field name="requisition_line_ids" nolabel="1" widget="one2many_list" >
                <tree string="Requisition Lines" editable="bottom">
                    <!-- 'mir.requisition.line' fields -->
                </tree>
            </field>
        </form>
    </field>
</record>

我希望这个答案对你有帮助。