Search code examples
python-3.7odoo-12

Is there a way to insert multiple records into one2many field


I'm trying to create a history for some data, I need to copy one2many values into another one2many field. The problem is im always getting only the last record

I have Tried to loop on each line of the one2many field

    def create_action(self):
        for agent in self:
            for line in agent.local_id:
                action_obj = self.env["historiq"]
                values = [(0, 0, {'localisation': value.localisation}) for value in line]
                historique = {
                'date_affectation': str(datetime.datetime.now()),
                'nom_agent': agent.agent_id.name,
                'post_occupee': agent.poste,
                'zone_affecte': values,}
                action_ids = action_obj.create(historique)

Solution

  • Is There any way of taking related one2many field than you can take related field it will copy all record of one2many.

    And can you show where you calling these function.