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

Поделиться
HTML-код
  • Опубликовано: 11 дек 2024

Комментарии • 33

  • @Mizo_Koki
    @Mizo_Koki 7 месяцев назад

    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

  • @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.

  • @ShadHastam
    @ShadHastam 10 месяцев назад

    thanks

  • @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?

  • @mohamedsobh2626
    @mohamedsobh2626 2 года назад +1

    api run if i put it between class and field

  • @Urbanbash-Lore
    @Urbanbash-Lore 10 месяцев назад

    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 5 месяцев назад

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

  • @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

  • @alimhanna9551
    @alimhanna9551 2 года назад

    how can i use compute to set many2many value ?

    • @OdooMates
      @OdooMates  2 года назад

      self.m2m_field = record_set.ids

  • @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 ?