24. How To Create Computed Field In Odoo 15 || Compute Field In Odoo 15 || Odoo 15 Development

Поділитися
Вставка
  • Опубліковано 5 січ 2025

КОМЕНТАРІ •

  • @Mizo_Koki
    @Mizo_Koki 8 місяців тому

    hello,
    i have a question
    after finishing making search panel in patient xm view , i finished work and turned my computer off.
    when i came to continue work on next day , i didn't find search filters or search panel on UI of odoo although they are still in my xml file on pycharm.
    what is the issue???

  • @SamirSELLAMI
    @SamirSELLAMI 2 роки тому +2

    is the use of the _ underscore symbole in the beginning of a compute method name (or any Odoo Python method) have a meaning or it is just a naming convention?

    • @OdooMates
      @OdooMates  2 роки тому +1

      there is people who defines computed function starting with an underscore and without underscore.

    • @SamirSELLAMI
      @SamirSELLAMI 2 роки тому +1

      @@OdooMates I don’t remember well, but I read an article mentioned that the use of _underscore in Python has relation with public vs private methods. So in Odoo it’s only a manner of naming convention. Thanks Bro.

    • @OdooMates
      @OdooMates  2 роки тому +1

      @@SamirSELLAMI yes _underscore method will be private and it cannot be accessed or triggered from outside, like what i can say, those functions cannot be called from xmlrpc for example

    • @SamirSELLAMI
      @SamirSELLAMI 2 роки тому +1

      @@OdooMates ah okay thanks

    • @OdooMates
      @OdooMates  2 роки тому

      Welcome brother

  • @alielnagar2
    @alielnagar2 Рік тому +1

    nice

  • @malikkamil6596
    @malikkamil6596 2 роки тому

    i want to show field from sale order to stock picking how can i do that

  • @ShadHastam
    @ShadHastam 11 місяців тому

    thanks

  • @DonTimo12
    @DonTimo12 2 роки тому

    Hi is it possible that there is a mistake in the calculation of the age field... there has not been taken in account that that today.month might be before the patients birthday in that year and the today.day might be before the patients birthday if today.month == rec.date_of_birth.month.

  • @OpenERPGolssary
    @OpenERPGolssary Рік тому

    thank you , I get this error AttributeError: 'Date' object has no attribute 'split' when use @api.depends(date_of_birth) , can you help please

  • @mohamedsobh2626
    @mohamedsobh2626 2 роки тому +1

    api run if i put it between class and field

  • @alimhanna9551
    @alimhanna9551 2 роки тому

    how can i use compute to set many2many value ?

    • @OdooMates
      @OdooMates  2 роки тому

      self.m2m_field = record_set.ids

  • @Urbanbash-Lore
    @Urbanbash-Lore 11 місяців тому

    i very like your tutorials, but i see a small issue here correct me if im wrong. :)
    The python code is not thinking through.
    It is only looking at the year, but this creates an issue.
    For exampel:
    Patient A born 01.03.1994
    Patient B born 01.09.1994
    current date 01.07.1994
    both will get the same age in the code.
    i guess most are aware of this but i needed it for my self to write this down :)

    • @HScreators99HScreators99
      @HScreators99HScreators99 6 місяців тому

      you didn't define the exact date field because of this it will get error

  • @abdullah-nasser-
    @abdullah-nasser- Рік тому +1

    Hi Odoo Mates
    Thanks for this tutorial, it's simple and clear
    I have question
    is there any difference if I wrote the _compute function with/out the `for record in self`
    because I made it like this, and it's working without any error
    @api.depends("DOB") # I named date_of_birth as DOB
    def _compute_age(self):
    today = date.today()
    self.age = today.year - self.DOB.year
    don't worry about the blank value of the DOB field, I defined a function to set it by default to 25 years back from current year.

    • @OdooMates
      @OdooMates  Рік тому

      thanks for the support, if it is a non stored compute field, can you add this to list view and see if there is any error

    • @abdullah-nasser-
      @abdullah-nasser- Рік тому

      @@OdooMates
      yeah, it appears, the singleton
      but isn't this loop is exhausting for the server?
      I'm imagining if I have a 10000 records, is it going to loop through them on every action I do on the UI?

  • @aadhishesanlakshmanan7354
    @aadhishesanlakshmanan7354 2 роки тому

    from datetime import date
    def _compute_age(self):
    for rec in self:
    today = date.today()
    if rec.date_of_birth():
    rec.age = today.year - rec.date_of_birth
    else:
    rec.age = 1
    Hi bro. This is my code. When i try to implement the above code i got a error, which is "date is not defined", kindly give me the solution for this.
    And for your reference "now I'm use odoo 13 version"

    • @OdooMates
      @OdooMates  2 роки тому

      Add from datetime import date at the top file to import date package

    • @aadhishesanlakshmanan7354
      @aadhishesanlakshmanan7354 2 роки тому

      def _compute_age(self):
      for rec in self:
      today = date.today()
      if rec.date_of_birth():
      rec.age = today.year - rec.date_of_birth
      else:
      rec.age = 1
      This is my code bro.
      age = fields.Integer(string="Age", compute='_compute_age')
      date_of_birth = fields.Date(string="Date of Birth", required=True)
      This is my fields bro.
      Also I'm import "from datetime import date" at the top.
      The error is 'type error :datetime.date' object is not callable
      Kindly give me the solution for this

    • @OdooMates
      @OdooMates  2 роки тому

      @@aadhishesanlakshmanan7354 try with: fields.Date.today()

    • @aadhishesanlakshmanan7354
      @aadhishesanlakshmanan7354 2 роки тому

      @@OdooMates ok bro thanks

    • @OdooMates
      @OdooMates  2 роки тому

      @@aadhishesanlakshmanan7354 welcome brother

  • @mohamedsobh2626
    @mohamedsobh2626 2 роки тому

    def _compute_gdays(self):
    for record in self:
    today = date.today()
    if record.start_date:
    record.gdays = today - record.start_date
    else:
    record.gdays = 1
    AttributeError: 'agri.projects' object has no attribute '_compute_gdays'

    • @OdooMates
      @OdooMates  2 роки тому

      did you restarted the service after adding the function ?