Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
470 Visualizações
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.


Avatar
Cancelar
Melhor resposta

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


Avatar
Cancelar