Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
4110 Vistas

i keep getting an invalid move id because of the move_line.write code here.
needing help, i don't understand what i'm missing or doing wrong:

def update_move_lines(self, move_id, **kwargs) -> http.Response: 

          line_data = json.loads(http.request.httprequest.data) 

          try: 

                 move_id = int(move_id) 

                 move = http.request.env['stock.move'].browse(move_id) 

                 if not move: 

                       raise UserError("Stock Move not found.")

                 existing_lines = move.move_line_ids 

                 existing_index = 0

                 for line_vals in line_data: 

                      quantity_done = line_vals.get('quantity') 

                      destination_package_id = line_vals.get('destination_package_id')

                      if existing_index (less than or equal) len(existing_lines) - 1: 

                             move_line = http.request.env['stock.move.line'].browse(existing_lines[existing_index].id) 

                            move_line.write({ 'qty_done': quantity_done, 'result_package_id': destination_package_id }) 

                            existing_index += 1 

                            logging.info('update_here') 

                     else: 

                            logging.info('create here')


               return response_template(status_code=200, status="success", data=line_data) 

        except ValueError: 

              raise UserError("Invalid Move ID.")

Avatar
Descartar
Mejor respuesta

Hi,

You can use the following code,


def update_move_lines(self, move_id, **kwargs) -> http.Response:

          line_data = json.loads(http.request.httprequest.data)

          try:

                 move_id = int(move_id)

                 move = http.request.env['stock.move'].browse(move_id)

                 if not move:

                       raise UserError("Stock Move not found.")

                 existing_lines = move.move_line_ids

                 existing_index = 0

                 for line_vals in line_data:

                      quantity_done = line_vals.get('quantity')

                      destination_package_id = line_vals.get('destination_package_id')

                      if existing_index (less than or equal) len(existing_lines) - 1:

                             move_line = http.request.env['stock.move.line'].browse(existing_lines[existing_index].id)

                            move_line.sudo().write({ 'qty_done': quantity_done, 'result_package_id': destination_package_id })

                            existing_index += 1

                            logging.info('update_here')

                     else:

                            logging.info('create here')

               return response_template(status_code=200, status="success", data=line_data)


        except ValueError:

              raise UserError("Invalid Move ID.")


Hope it helps,



Avatar
Descartar
Mejor respuesta

hello

as you are from a controller, the crud (create read update delete) right should be set to read only so change the group ruel or do a sudo in your write method

don't think it's a good idea to do a sdo here (check your securty route and use token and user)

Annabelle

Avatar
Descartar
Autor Mejor respuesta

ok i think i figured it out. i should do this instead.

move_line = http.request.env['stock.move.line'].browse(existing_lines[existing_index].id) 

move_line.quantity = quantity_done 
move_line.result_package_id = destination_package_id

can someone explain why .write doesn't work though? :/

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
ago 25
184
4
may 25
2515
2
may 25
5880
4
abr 25
7551
1
mar 25
1693