How To Update One2many Field From OnChange Of Field in Odoo

Поділитися
Вставка
  • Опубліковано 31 жов 2024

КОМЕНТАРІ • 105

  • @justinstar9710
    @justinstar9710 4 роки тому +2

    Great tutorial
    I think its also worth noting, Odoo is going to sequentially execute each tuple in the list for One2many field.
    Adding the possibility to NOT only create new or replace exist.

  • @ThatOdooGuy
    @ThatOdooGuy 4 роки тому +1

    I hardly subscribe to any channel. But you are really doing a great job. Keep it up! I hope to learn a lot from you.

  • @dabhijaydeep
    @dabhijaydeep 4 роки тому +1

    Hi,
    (0, 0, { values }) link to a new record that needs to be created with the given values dictionary
    (1, ID, { values }) update the linked record with id = ID (write *values* on it)
    (2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
    (3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
    (4, ID) link to existing record with id = ID (adds a relationship)
    (5) unlink all (like using (3,ID) for all linked records)
    (6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)
    Explain what the use of all of this. Just little bit confused.

  • @Jose-tw9bl
    @Jose-tw9bl 3 роки тому

    Super usefull! i was just trying to write one2many field in a wizard, and i had no idea about how to do this! thanks!

  • @subhamaharjan
    @subhamaharjan 3 роки тому +2

    Thanks for making this video. :D

  • @ivansetiawan2023
    @ivansetiawan2023 3 роки тому +1

    Thank u so much. Very helpful

  • @abdelhalimkaddourguettaoui4591
    @abdelhalimkaddourguettaoui4591 4 роки тому +2

    Great tutorial

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

    Thank you!

  • @ahmedharoon2740
    @ahmedharoon2740 3 роки тому

    very nice, great explaination, this will be very useful... can i add a Many2one type Transient field in model? if yes, how i can create in Model and use it in view, I do not want to store its data in database. AND please also give the link of your video for adding Sequence for a field, as i forgot what was the link actually. be blessed :)

  • @LBONLINETV
    @LBONLINETV 3 роки тому

    Hello, I have three fields ex: request_qty = 4, deliver_qty = 4 and total_qty = 0, how can i automatically add deliver_qty values to total_qty . Because i want users to always request for stock qty after sales and once manager deliver_qty is should automatically add up on user total_qty field. How can i achieve this function?

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

    Added One2many in crm lead form page as a notebook page. now i want to show this One2many fields value into sale order One2many fields. can you help me

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

      create a one2many in sale order model, and pass the value from the crm lead to sale order via sale order creation method in lead

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

      @@OdooMates ok thanks I will try. Is there any video or documents for the same?

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

      @@surekhapalani6511 not specifically for this, but if we have strong idea in odoo orm, it is easy, ua-cam.com/video/8V-uOG8KkKA/v-deo.html

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

    Do you have away to post chatter tracking in product order line in field one two many ??

  • @aliabdulla3
    @aliabdulla3 4 роки тому +1

    i cant watch "all" of the video right now sadly, but i wanted to ask the question before i forget
    every time u select a product template u add "1" product, can we have for example a package template, when i choose it it will automatically add the package productS .. for example i want to send supplies
    i can choose the supply package which includes stocks and shipping
    or i want to do a training, so i need hall booking, refreshments, perdiam for each participants, etc etc

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

      yes you can add multiple products at a time, thats why we have used for loop, it is shown in the video itself, if you watch fully, you can see it :)

    • @aliabdulla3
      @aliabdulla3 4 роки тому +1

      @@OdooMates thank you for the confirmation , awesome!

  • @ammarhassanabdelgadeir9399
    @ammarhassanabdelgadeir9399 4 роки тому +2

    ok what is the difference between this and related?

  • @ganbaatarburiad400
    @ganbaatarburiad400 4 роки тому +1

    Hello Sir, What is the difference between product_product and product_template?. It is so confused for me. :)

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

      These are two tables in Odoo to handle product and product variants... For every record in product template you will have atleast one record in product. Product

  • @Akbarali-ik1sc
    @Akbarali-ik1sc 4 роки тому +1

    In this video,one2 many updated accordingly to the specific many 2 one field.I am change the onchange many 2one filed to many2many.Data is fetched to the one2 many line but not able to save.It shows no implement error How can I done that?.pls reply :)

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

      can you show your code please

    • @Akbarali-ik1sc
      @Akbarali-ik1sc 4 роки тому

      @@OdooMates
      class Billingrateform(models.Model): _name = "billing.rate" _rec_name = 'project_id' project_id = fields.Many2one('account.analytic.account', string="Project") billing_date = fields.Date(string="Date", default=datetime.today()) start_date = fields.Date(string='Start date') end_date = fields.Date(string='End date') days_id = fields.Float(string='Days', compute='_compute_worked_days', store=True, readonly=True) demos_id = fields.One2many("billing.tree", "line_id") @api.onchange('project_id') def _check_employee_id(self): for rec in self: lines= [(5, 0, 0)] for line in self.project_id.line_ids: vals = { 'employee_id': line.employee_id, 'unit_amount': line.unit_amount, 'cost_id': line.timesheet_cost_id / 100 * line.add_cost + line.timesheet_cost_id, 'timesheet_cost': line.timesheet_cost_id, 'oper_cost': line.add_cost, 'percentage_id': line.timesheet_cost_id / 100 * line.add_cost, 'total_id': line.timesheet_cost_id * line.unit_amount + line.timesheet_cost_id / 100 * line.add_cost } lines.append((0, 0, vals)) rec.demos_id = lines print(lines, "val")

    • @Akbarali-ik1sc
      @Akbarali-ik1sc 4 роки тому

      I dont know which way I can present the code.Can you give me a mail.

    • @AdeshPaul
      @AdeshPaul Місяць тому

      I also faced same problem. Later if noticed that one2many field was readonly therefore I put force_save="1"

  • @sooryalakshmikt4894
    @sooryalakshmikt4894 10 місяців тому

    But at the time of saving all the records under one2many field is removing. Why?

  • @esamgamal2750
    @esamgamal2750 4 роки тому

    Why when adding all records is erased and only one is added?
    @api.onchange('idtrans')
    def _onchange_idtrans(self):
    for rec in self:
    lines = [(5, 0, 0)]
    # lines = []
    for line in self.idtrans:
    print('type', type(line))
    print('type_id',type(line.id))
    val = {
    'idtrans':line.id,
    'amount': 5,
    'date': datetime.today()
    }
    lines.append((0, 0, val))
    print('lines_new:',lines)
    rec.idpayamount = lines

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

      Remove this line lines = [(5, 0, 0)]
      and simply give [] and see

    • @esamgamal2750
      @esamgamal2750 4 роки тому

      @@OdooMates I tried what she told me and the problem still exists
      lines=[]
      val = {
      'idtrans': self.idtrans.id,
      'amount': 5,
      'date': datetime.today()
      }
      lines.append((0, 0, val))
      self.idpayamount = lines

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

    Hi,
    How can i onchange the one2many fields depending on the other page one2many fields?could you please help

  • @supreetlaghate22
    @supreetlaghate22 3 роки тому +1

    Hello. how to get bydefault all medicines when many2one field is blank?

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

      in the one2many lines ? see: ua-cam.com/video/BSL4iOHZ-Rc/v-deo.html

  • @ashwinstephen7292
    @ashwinstephen7292 3 роки тому +1

    Sir, could you tell me how to delete unsaved newobject id lines in onchange.

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

      Will this help ? ua-cam.com/video/2pOIxhE_xuY/v-deo.html

  • @learnwithus344
    @learnwithus344 3 роки тому

    I have a model with me in which a one2many field of products is added below the many2one field of customer. i need this one2many field of product lines to be automatically fetched when i select the particular customer in another module. How can I do this with the onchange function? please help me ASAP

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

      is the onchange of the customer happening in the same model that contains the one2many field ?

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

      @@OdooMates i have a model with customer details (name, company etc ) and a one2many field below that (it is defined as a separate model). After that when i choose the customer details say customer name in another module say like sale module (sale order form) , the earlier one2many field must be automatically coming.....

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

      By an onchange function you can achieve it

  • @ambarishakn82
    @ambarishakn82 4 роки тому +1

    Unable to add below record to one2Many on compute method in Odoo 13.
    [(5, 0, 0), (0, 0, {'employee_id': 'Mitchell Admin', 'worked_hours': 10.0030555555556, 'percentage': 0})]
    ------------------------------------------------------------------------------------------------------------------------------------------------
    detail_list = fields.One2many('ndr.project.detail', 'project_name', string='Details',
    compute='_calculate_project_details')
    ------------------------------------------------------------------------------------------------------------------------------------------------

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

      You have any error message ?

  • @vrindhavinoj2222
    @vrindhavinoj2222 3 роки тому +1

    How can we update salesorderline with details from my custom module?

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

      if you have sale.order.line object, using object.field_name = 'value' or object.write({'field': value}) , you can update the record

    • @vrindhavinoj2222
      @vrindhavinoj2222 3 роки тому +2

      ​@@OdooMates Can u try to make a video on that,onchange in existing views like saleorderline

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

      @@vrindhavinoj2222 hope you already achieved as per mail conversation

    • @vrindhavinoj2222
      @vrindhavinoj2222 3 роки тому +2

      @@OdooMates Yes sir..

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

      im having same problem. can you explain to me what is the solution.

  • @ashwinstephen7292
    @ashwinstephen7292 3 роки тому +1

    I coundnt add lines. only replacing with existing lines
    @api.onchange('app_order_ids')
    def on_change_app_id(self):
    for rec in self:
    lines = []
    for line in self.app_order_ids.top_lines:
    val={'article_name':line.name}
    lines.append((0,0,val))
    rec.grn_order_lines = lines

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

      version ?

    • @ashwinstephen7292
      @ashwinstephen7292 3 роки тому

      @@OdooMates 10.0

    • @ashwinstephen7292
      @ashwinstephen7292 3 роки тому +1

      any solution for version 10?

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

      @@ashwinstephen7292 the above video was illustrated in v12

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

      For V10, try as follows:
      vals = {
      'field_1': value,
      'field_2': value,
      }
      self.one2_many_field_name += self.one2_many_field_name.new(vals)

  • @nromenero9508
    @nromenero9508 4 роки тому +1

    I am facing a problem
    I am using the code from this tutorial to
    add a product to the `recurring_invoice_line_ids` in sale.subscription
    but I am going this error `(Record: product.product(154,), User: 2)`(Record: product.product(154,), User: 2)

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

      Can you show ur codes

    • @nromenero9508
      @nromenero9508 4 роки тому +1

      I tried asking on odoo form and stackoverflow but not one is answering me can u plz help

    • @nromenero9508
      @nromenero9508 4 роки тому +1

      @@OdooMates
      supsctiption_pak = self.env['product.template'].search([('name', '=', pak_name),('recurring_invoice', '=', True)], limit=1)
      supsctiption_info = {
      'partner_id': vals['name'],
      }
      add_supsctiption = self.env['sale.subscription'].create(supsctiption_info)
      print('sb',supsctiption_pak.name)
      print('sb1',vals['name'])
      # print('sb2',vals['name'].name)
      supsctiption_to_pak = self.env['sale.subscription'].search([('partner_id', '=', vals['name'])], limit=1)
      print('sb3',supsctiption_to_pak)
      print('sb3',supsctiption_to_pak.display_name)
      add_supsctiption_pak = {
      'product_id': supsctiption_pak,
      }
      supsctiption_to_pak.write({'recurring_invoice_line_ids':[(5, 0, 0),(0,0,add_supsctiption_pak)]})

    • @nromenero9508
      @nromenero9508 4 роки тому +1

      @@OdooMates
      I am using the create function from my custom module
      since on-change Is only cared from the UI

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

      self.env['product.template'].search([('name', '=', pak_name),('recurring_invoice', '=', True)], limit=1) change product.template to product.product and see

  • @sansoftinfotech-career9282
    @sansoftinfotech-career9282 3 роки тому

    what are the columns in the odoo AccountType master , documentType master and how these are accessed in a code ?

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

      if you activate developer mode and navigate go to Settings -> Technical -> Database Structure -> Models, search for the models and open it, then you can see all the fields/columns in the table/model

  • @عبدربايعة-ح5ض
    @عبدربايعة-ح5ض 3 роки тому

    Hi i need to update data from fields i input without use many2one in product_id can you display that?
    Thanks 😊

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

      can you elaborate little more

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

    hello,
    i had a problem with that
    class parent()
    field category_id many2one product.category
    field child_ids one2many
    class child ()
    field parent_id many2one
    field product many2one product.template
    in xml or py
    in need to filter the product to; select product from its category
    how to pass domain?

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

    Like this,I want to add more products,can you help me in this
    Thank you.

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

    hello I would like to do the same but do it from one One2Many to another One2many

  • @charoliyamujahid526
    @charoliyamujahid526 4 роки тому +1

    Please Make js video

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

      Will be publishing today :)

  • @dzaround
    @dzaround 3 роки тому +1

    please leave me here the link to the git repesotery

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

      github.com/odoomates/odooapps

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

      github.com/odoomates/Development-Tutorials

    • @dzaround
      @dzaround 3 роки тому +1

      @@OdooMates thankyou for this tutorial, Algeria :)

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

      @@dzaround welcome from India :)

    • @dzaround
      @dzaround 3 роки тому +1

      @@OdooMates i folowed the tuto and i trie to do the same thing into my project like this:
      class fleet_carnet_essnece_ayoub(models.Model):
      _name = 'fleet_affectation_ayoub.fleet_carnet_essnece_ayoub'
      _description = ' Creation carnet de bons d essence'
      ...............

      Many2one_carnet_field = fields.Many2one ('fleet_affectation_ayoub.fleet_creation_bon_essnece_ayoub')
      class fleet_bon_essnece_ayoub(models.Model):
      _name = 'fleet_affectation_ayoub.fleet_bon_essnece_ayoub'
      _description = " Bons d'essence"
      ..................................
      carnet = fields.Many2one ('fleet_affectation_ayoub.fleet_carnet_essnece_ayoub', string ='Carnet', required="True")
      bon_line = fields.One2many ('fleet_affectation_ayoub.fleet_creation_bon_essnece_ayoub', 'carnet_ids', string ="Ligne de bons")
      @api.onchange('carnet')
      def on_change_carnet(self):
      for rec in self:
      lines =[]
      print ("self.carnet", self.carnet.on2many_carnet_field )
      # for line in self.carnet
      rec.bon_line = lines
      class fleet_creation_bon_essnece_ayoub(models.Model):
      _name = 'fleet_affectation_ayoub.fleet_creation_bon_essnece_ayoub'
      _description = 'ligne des bons '
      bon_qty = fields.Integer(string="Quantity")
      carnet_ids = fields.Many2one('fleet_affectation_ayoub.fleet_bon_essnece_ayoub', string='joined')
      bon_id = fields.Integer(string="Numero de bon")
      carnet_id = fields.Many2one('fleet_affectation_ayoub.fleet_carnet_essnece_ayoub', string='joined')
      on2many_carnet_field = fields.One2many('fleet_affectation_ayoub.fleet_carnet_essnece_ayoub', 'Many2one_carnet_field', string='joined')
      and i recieved the folowing error :
      File "/opt/odoo/odoo-10.0/addons/fleet_affectation_ayoub/models/models.py", line 234, in on_change_carnet
      print ("self.carnet", self.carnet.on2many_carnet_field )
      AttributeError: 'fleet_affectation_ayoub.fleet_carnet_essnece_ayoub' object has no attribute 'on2many_carnet_field'
      Also i want to know the way that you retriev values from product.variant
      Thankyou brother

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

    how to calculate the entered value in one2many field (example:in this video how to calculate that quantity of product in total)

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

      ua-cam.com/video/0mHM_EPT6Fw/v-deo.html

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

      ua-cam.com/video/8V-uOG8KkKA/v-deo.html

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

    not working, is the same and i get newID object

  • @thanshidhap.p4743
    @thanshidhap.p4743 3 роки тому

    How can i inherit the same One2many field in different class? Please help me

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

      just change the connecting many2one field

    • @thanshidhap.p4743
      @thanshidhap.p4743 3 роки тому

      @@OdooMates i can't get you. I want to use the same one2many field in another submenu. Can u describe me

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

      @@thanshidhap.p4743 is it in the same model or different model ?

    • @thanshidhap.p4743
      @thanshidhap.p4743 3 роки тому

      @@OdooMates different class, same py file

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

      @@thanshidhap.p4743 then take a copy of one2many field definition from the first model and place it in the second model/class, the only thing that you need to change is the many2one field

  • @AlbertoPoljak
    @AlbertoPoljak 3 роки тому +1

    HAHA let's make crap ORM with magic numbers and shit documentation - some Odoo dev probably

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

      You mean video not helpful ?