This question has been flagged

I've managed to create a transfer (stock.picking) record and, through setting the Stock Moves field in the transfer, a stock.move record.

The trouble is that, despite the stock.move being created as a field in the stock.picking record, the two resulting records appear to be unrelated:

•    The Transfer record has nothing in its move lines
•    The Stock Move record has "Stock Rule/External ID" = FALSE

Below is are details of the current Automated Action setup.  Any advice/guidance/resource-links would be greatly appreciated:

My automated action intent is to create a stock transfer (stock.picking) under certain conditions (in this case if a "quantity_rejected" number field changes from 0 to a number >0):

I create a new automated action with the following settings:

  • Action To Do: Create a new Record
  • Create/Write Target Model: Transfer

Under the "Data to Write", I have the following:

FIELD (stock.picking)

EVALUATION TYPE

Record / Value

Company

Reference

MyCompany

Source Location

Reference

WH/Input

Destination Location

Reference

WH/Scrap

Operation Type

Reference

MyCompany: Internal Transfer

Source Document

Python expression

record.x_name

Qty

Python expression

record.x_studio_quantity_rejected

Product

Python expression

record.x_studio_product.id

Stock Moves
Python expression
env['stock.move'].create({
'name': 'Rejected Product Transfer',
'location_id': 14,
'location_dest_id': 20,
'product_id': record.x_studio_product.id,
'product_uom': 1,
'product_uom_qty': record.x_studio_quantity_rejected,
'procure_method': 'make_to_stock',
'date_expected': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
'company_id': 1,
})


As I say, this successfully creates both a new transfer, and a new stock move record.  But, like I say, despite the stock.move being created as a field in the stock.picking record, the two records appear to be unrelated:
•    The Transfer record has nothing in its move lines
•    The Stock Move record has "Stock Rule/External ID" = FALSE


(Odoo v12 Enterprise)

Avatar
Discard

Did you manage to find a solution for this?

Author

Unfortunately, no.  Experimented a bit more, but never found a solution. Ultimately I gave up.

Would still be really nice to know how to accomplish this though... ;)

Best Answer

Hi,

I managed to do this the following way.

You are creating a new record in the table stock.move, whereas using the transfer['move_lines'] i'm creating it in the context of the transfer.

----------------------------------

destination = record.location_id
orderlines = record.move_lines
note = "Nieuwe Transfer"
id = record.id

transfer = env['stock.picking'].create({
'picking_type_id': 5,
'location_id': 8,
'location_dest_id' : destination.id,
'note' : note
})

for line in orderlines:
transfer['move_lines'] = [(0,0, {
'name' : note,
'product_uom_qty' : line.product_uom_qty,
'product_id' : line.product_id.id,
"product_uom" : line.product_id.uom_id.id,
"location_id" : 8,
"location_dest_id" : destination.id
})]

Avatar
Discard