Odoo10 - Inherit Model to TransientModels with Many2Many Fields

50 Views Asked by At

I have odoo model which contain m2m and o2m fields as shown below:

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)

then i want to allow user to input through Wizard also (user can add or edit), with the same condition and validation that exists in this model. i know we can do by create new transientmodel and copy and paste the same code, but it will be hard for me to maintain it, if there any changing of validation in the master tables.

is it possible to use inheritance for this case? so basicly i want to have all model field in transientModel

Any advice will help. thanks in advance

1

There are 1 best solutions below

0
Ahrimann On

You can manage it using a many2one field ("sap_model") on your original model ("sap.pl.outstanding.comment") and related fields for each needed fields of this original 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, that are associated with the needed fields of your basis model:
     rel_plant_id = fields.Many2one(related='sap_model.plant_id',string='Department')
     rel_period_id = fields.Many2one('sap_model.period_id', string='Month')
     #...
     #...