Comment 2 for bug 1066127

Revision history for this message
Ravi Gohil (OpenERP) (rgo-openerp) wrote :

Hello Alexis de Lattre,

We really appreciate your efforts for detailed explanation, the analysis you did and also for the patch.

However, in your fix, there is a small mistake,

- if picking_obj.invoice_state == 'invoiced':
+ if 'invoice_state' not in default and picking_obj.invoice_state == 'invoiced':
   default['invoice_state'] = '2binvoiced'

With your fix, the code in the `if` block will never execute as the condition you placed will check for the `invoice_state` key in `default` dictionary, but, when the copy() is called from /stock/wizard/stock_return_picking.py line 171, `invoice_state` key set statically, so the condition `if 'invoice_state' not in default` will never be true.

The reason why it works at your end is, the `Return Products` wizard will send the value for it's `invoice_state` field that is, `none` or `2binvoiced` and this value is going to be sent in `default` dictionary in /stock/stock.py line 702, and the returned picking will be created and it's `Invoice Control` field will have the value of `invoice_state` dict.

As per my investigation, this condition is not needed, because, whatever the `invoice_state` selected in `Return Products` wizard, that should be set in the `Invoice Control` in returned picking! or the fix could be modified like,

- if picking_obj.invoice_state == 'invoiced':
+ if default['invoice_state'] != 'none' and picking_obj.invoice_state == 'invoiced':
   default['invoice_state'] = '2binvoiced'

But, as per my opinion, the condition is not needed, hence I will prefer to fix by removing this condition and will create a branch.

@Alexis de Lattre: Thanks for your analysis which traced the root cause of the issue.