Odoo10 - 将模型继承到具有 Many2Many 字段的 TransientModels

问题描述 投票:0回答:1

我有odoo模型,其中包含m2m和o2m字段,如下所示:

class SapPlOutstandingComment(models.Model):
    _name = "sap.pl.outstanding.comment"
    _description = "PL Manual Outstanding Comment"
    _rec_name = "plant_id"

    plant_id = fields.Many2one('sap.mm.plant',string='Department', ondelete='restrict')
    period_id = fields.Many2one('account.period', string='Month', ondelete='restrict')
    description = fields.Many2one('sap.pl.id.mapping',string='Description', ondelete='restrict')
    category = fields.Many2one('sap.pl.comment.category',string='Category', ondelete='restrict')
    currency_id = fields.Many2one('res.currency', string='Currency', default=lambda self: self.env.user.company_id.currency_id)
    amount = fields.Monetary(string='Amount')
    action = fields.Selection([('take out/add in', 'Take Out/Add In'), ('move', 'Move')], string="Type of Comments")
    reconcile = fields.Boolean(string="Reconcile", default=False)
    reconcile_comment = fields.Many2many('sap.pl.outstanding.comment','sn_sap_pnl_oc_reconcile_rel', 'sap_pl_outstanding_comment_id','reconcile_comment_id', string='Outstanding Comment')
    move_to = fields.Many2one('sap.pl.id.mapping', string='Move To', ondelete='restrict')
    reason = fields.Text(string="Reason")
    status = fields.Selection([('open', 'Open'), ('closed', 'Closed')], string="Status", default="open")
    close_comment = fields.Boolean(default=False)
    can_select_action = fields.Boolean(default=False)
    can_close_comment = fields.Boolean(default=False)

然后我想允许用户也通过向导输入(用户可以添加或编辑), 具有与该模型中存在的相同条件和验证。我知道我们可以通过创建新的瞬态模型并复制并粘贴相同的代码来完成,但是如果主表中的验证有任何更改,我将很难维护它。

在这种情况下可以使用继承吗? 我的意思是如果我在transientModel中继承这个模型?

任何建议都会有所帮助。 预先感谢

python orm odoo odoo-10
1个回答
0
投票

您可以使用原始模型(“sap.pl.outstanding.comment”)上的 Many2one 字段(“sap_model”)以及该原始模型的每个字段的相关字段来管理它:

class SapPlOutstandingWizard(models.TransientModel):
    _name = 'sap.pl.outstanding.wizard'
     
     # Many2One field to link to your basis model:
     sap_model= fields.Many2one('sap.pl.outstanding.comment', string="basis model")
     
     # Related fields (associated with the needed fields of your basis model:
     model_plant_id = fields.Many2one(related='sap_model.plant_id',string='Department')
     model_period_id = fields.Many2one('sap_model.period_id', string='Month')
     #...
     #...

© www.soinside.com 2019 - 2024. All rights reserved.