简体   繁体   English

从另一张表继承一张表

[英]inherit one table from another

I want to inherit an entire table to a new table, I have tried as follows but it doesn't work for me.我想将整个表继承到一个新表,我尝试过如下但它对我不起作用。

the table to inherit is as follows:要继承的表如下:

class Detalle_libro(models.Model):
    _name='proyecto_rc.detalle_libro'

    date=fields.Datetime(string="Fecha", related='tipo_movimiento_id.fecha', store=True)
    account_credit= fields.Char(string="Cuenta haber", related='cuenta_id.cuenta_haber1', store=True)
    total_debit=fields.Float(string="Debe", compute="_total_a_debe", inverse="_inverse_debe" , store=True)
    total_credit=fields.Float(string="Haber", compute="_total_a_haber", inverse="_inverse_haber" , store=True)
    account_id = fields.Many2one(comodel_name='proyecto_rc.account', string='Cuenta')

new table:新表:

class Libro_diario(models.Model):
    _inherit = 'proyecto_rc.detail_book'

    date = fields.Datetime(string="Fecha")
    account_debit = (res.cuenta_id)
    account_credit = fields.Char(string="cuenta haber")
    total_debit=fields.Float(string="Debe")
    total_credit=fields.Float(string="Haber")

in the view:在视图中:

    <record model="ir.ui.view" id="proyecto_rc.libro_inherit">  
    <field name="name">list of book</field>
    <field name="model">proyecto_rc.datail_book/field>
    <field name="inherit_id" ref="proyecto_rc.detail_book_form"/>
    <field name="arch" type="xml">
        <field name="date"/>
        <field name="cuenta_debit"/>
        <field name="cuenta_credit"/>
        <field name="total_debit"/>
        <field name="total_credit"/>
    </field>
    </record>

    <record model="ir.ui.view" id="proyecto_rc.tree_detail_book_list">  
    <field name="name">list of book</field>
    <field name="model">proyecto_rc.detail_book</field>
    <field name="arch" type="xml">
    </field>
    </record>

    <record model="ir.actions.act_window" id="proyecto_rc.detail_book_action_window">
    <field name="name">add book</field>   
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">proyecto_rc.detail_book</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree</field>
    <field name="view_id" ref="proyecto_rc.tree_detail_book_list"/>
    </record>

    <menuitem name="Libro"
    id="proyecto_rc_libro_diario" 
    parent="menu_proyecto_rc" 
    action="proyecto_rc.detail_book_action_window"
    groups="proyecto_rc.grupo_administrador,proyecto_rc.grupo_cajera"/>

This is ODOO 12

Try below code if you want to inherit a table and copy as new one.如果您想继承一个表并复制为新表,请尝试下面的代码。 copying existing model features and store in new table.复制现有模型特征并存储在新表中。

class Newmodel(models.Model):
_name = 'new.model'
_inherit = 'existing.model'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM