Skip to Content
Menu
This question has been flagged
2 Replies
2207 Views

I've made 3 models

class Budget(models.Model):

          _name = 'budget.model'

          value = fields.Integer()

          description = fields.Text()

          name = fields.Char()


class Ot(models.model):

          _name = 'ot.model'

            budget = fields.Many2one('budget.model')

            description = fields.One2Many('ot.model.desciption', 'ot_description')


class OtDescription(models.model):

        _name = "ot.model.description"

        ot_description = fields.Many2one('ot.model')

        quantity = fields.Integer()

        value    = fields.Integer()

        description= fields.Text()

    

I would like to show description, value, and quantity = 0 from budget.model inside the description field of ot.model when someone click the budget field of ot.model

I've tryed something inside ot.model

@api.onchange('budget')

def _onchange(self)

    if self.budget:

        self.desciption = self.env['ot.model.description'].search([])

but It's wrong

Avatar
Discard

Dear wildhen,

what is the relation betweet ot.model.description and budget.model. ?

You do one thing, create a budget field in ot.model.description.

Then you can search the description in on-change function.

Best Answer

Hello Wildhen,

This query will return an empty object of the model "ot.model.description".

You need to fetch the data to assign to this field.

You can try this.

def _onchange(self):
    if self.budget:
        objs = self.env["ot.model.description"].search([])
        if objs:
            self.description = [(6, 0, objs.ids)]
I hope this will resolve your query.


Thanks,

Aman Prakash (Associate Software Engineer)

Webkul Software Private Limited

Avatar
Discard