Skip to Content
Menu
This question has been flagged

Context:

Hi, I'm trying to make a computed field that sums up another computed field inside move_line_ids_without_package in the module stock.picking


In the list view of move_line_ids_without_package I created a field called sale_price that calculates the total of the sale price of the sale order and multiplies it by the qty_done giving me the total.


Now. I computed another field called x_studio_total_entrega_iva hosted out of the list view in stock.picking.



Field name: x_studio_total_entrega_iva

Model: Transfer

Field type: float

Dependencies: location_id

Compute: 

for record in self:
    if 'move_line_ids_without_package' in self._fields:
       for precio in self.move_line_ids_without_package:
            recor['s_studio_total_entrega_iva'] += precio.sales_price
       else:
            record['x_studio_total_entrega_iva'] = -1.0

Problem:

On transfers / delivery orders that are validated or Done the computed field works just fine.

On those that are Drafts, Waiting, or Cancelled and an error occurs that cannot compute the field because there isn't move_line_ids_without_package displayed.

The error also occurs when trying to create an internal transfer between warehouses. 


Traceback (most recent call last):
  File "/home/odoo/src/odoo/14.0/odoo/http.py", line 641, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/odoo/src/odoo/14.0/odoo/http.py", line 317, in _handle_exception
    raise exception.with_traceback(None) from new_cause
ValueError: Compute method failed to assign stock.picking(2386,).x_studio_total_entrega_iva


Any insights would be appreciate it or possible solutions.

Avatar
Discard
Best Answer

Hi,

It seems you have given the else condition inside the for loop, try to intend the else with if condition and see.

Please adjust the indentation of the python code as follows:

for record in self:

    if 'move_line_ids_without_package' in self._fields:
       for precio in self.move_line_ids_without_package:
            recor['s_studio_total_entrega_iva'] += precio.sales_price
    else:
         record['x_studio_total_entrega_iva'] = -1.0


Reason and solution: https://www.youtube.com/watch?v=Mz35lKuSUX0&list=PLqRRLx0cl0hoiTewSTzSQ3HJ-Vqhh43k0&index=15

Thanks

Avatar
Discard
Author

Hi Niyas, thanks for the feedback. I'm currently making sure there isn't any troubleshooting needed in any of the transfer-type documents. For now, especially in delivery orders is working just fine. Thanks again!

Related Posts Replies Views Activity
1
May 21
2598
0
Feb 16
2771
0
Jun 23
1035
2
Aug 22
3435
2
Jul 22
4919