This question has been flagged

Hi,

I'm playing with stock.picking model, called from Odoo 10 Web API.

I do the following after writing at least one stock.pack.operation :

res = odoo_model.execute_kw(
odoo_conf['db'],
odoo_uid,
odoo_conf['password'],
'stock.picking',
'put_in_pack',
[[int(picking['id'])]])

Everything works fine, I can see my prepared stock.pack.operation packed into stock.quant.package objects

My issue is I would like to get the IDs of created stock.quant.package.  I though that res could be affected the corresponding object as the source of the put_in_pack method is coded as follow :

@api.multi

def put_in_pack(self):

# TDE FIXME: reclean me

QuantPackage = self.env["stock.quant.package"]

package = False

for pick in self:

operations = [x for x in pick.pack_operation_ids if x.qty_done > 0 and (not x.result_package_id)]

pack_operation_ids = self.env['stock.pack.operation']

for operation in operations:

pass # Simplified this for you who is reading this thread

if operations:

pack_operation_ids.check_tracking()

package = QuantPackage.create({})

pack_operation_ids.write({'result_package_id': package.id})

else:

raise UserError(_('Please process some quantities to put in the pack first!'))

return package

Here the package object is returned at the end of the method, but res (result of execute_kw) is always False.

Is there something to do to retrieved the stock.quant.package just created?

Thanks.

Avatar
Discard
Best Answer

Hi Maxime,

I suppose you get False as return value because package is an instance of an empty record.

The following line of code creates a new QuantPackage record.

package = QuantPackage.create({})

Because you do not assign any value to the newly created record, you get False as result.

Try to assign some dummy values to the record before the return statement to see if my guess is correct.


Regards

Yvan

Avatar
Discard