I am trying to access a one2many field from a specific model and display it in another one, both models already exist and I am applying few changes to them. I inherited the first model and added a button to it and upon pressing it, this button should manipulate my one2many field from another model and here is the code, any help concerning this :
from odoo import models,api,fields
class Approval(models.Model):
_inherit = "approval.request"
line_ids = fields.One2many('purchase.requisition.line', 'requisition_id', string='Products to Purchase', states={'done': [('readonly', True)]}, copy=True)
product_line_ids = fields.One2many(related='line_ids.product_id', string='Type')
def purchase_agreement(self):
for rec in self:
lines = []
for line in rec.product_line_ids:
vals = {
'line_ids': line.line_ids,
}
lines.append((0, 0, vals))
rec.product_line_ids = lines
class PurchaseReq(models.Model):
_inherit="purchase.requisition"
Maybe try this one :
upon pressing
purchase_agreementbutton, theself.product_line_idswill assign itself through backend withrec.line_idsbased on user's selection inline_ids. Later on, to make the previous changes also work in the front end,self.product_lines_ids = self.line_idswill do.Please let me know the update