I would think to process as it would have been done with manual entry.
In settings for manufacturing you must have flagged "Unlock manufacturing orders" to allow flexible consumption.
Be sure that you have set Flexible Consumption to Allowed in the BOM, and Manual consumption is flagged for the components. (I assume you do not.
You must make sure you have filled the field qty_done in the stock move line for the components, which is the actual consumed qty. Else you will only post what is planned.
For produce fill the field qty_producing in mrp.production.
The result should be that the order get status = To close (field state in mrp.production).
Use the action "button_mark_done" and (of course) select only the actual manufacturing order. You will use the standard Odoo processing. It will do several posting in the background: Material movements, Accounting entries, and product valuation. So you should not need to send anything to stock valuation layer or stock.move.
But for Button Mark done action I have configured an automatic action, that run when field state is changed into "To Close".
model.search([('state', '=', 'to_close')]).button_mark_done()
Why do you update in product.template? Product template is masterdata, and it is not logic to update when processing confirmation of manufacturing?
Hope this helps you.