Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
481 Lượt xem
They would help me to take only the values ​​of a column that is in a table of one model to another table that is in another model, but I only need the values, without needing to call the entire table, just the columns.


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

HELLO,


Trying this 


transfer only the values of a specific column from one model's table to another model's table in Odoo, you can follow these steps.

For Example :

Below is an example that assumes:

  • Source model: source.model
  • Column in source model: source_field
  • Target model: target.model
  • Column in target model: target_field


     If Need the python code : 

from odoo import models, api


class TransferValues(models.TransientModel):

    _name = 'transfer.values.wizard'


    @api.model

    def transfer_column_values(self):

        # Step 1: Query the values from the source model

        source_records = self.env['source.model'].search_read([], ['source_field'])

        column_values = [rec['source_field'] for rec in source_records if rec['source_field']]


        # Step 2: Insert values into the target model

        for value in column_values:

            self.env['target.model'].create({'target_field': value})


        return True


Ảnh đại diện
Huỷ bỏ