Skip to Content
Menú
This question has been flagged
3 Respostes
2640 Vistes

Hi,


We have added new fields for mrp.bom.line for example width and height. User can define those and stock.move has the same fields. 

We would like to transfer bom.line fields to stock.move when user selects bom in production. I know that we can use compute function and it works okey.

Question: What is the right way in Odoo to transfer these details when generating move_raw_ids.


Here is the way to do it from sale.order.line to stock.move in picking.

https://stackoverflow.com/questions/55528616/how-to-send-custom-value-from-sale-order-line-to-stock-move-in-odoo

Avatar
Descartar
Autor Best Answer

Yep, thats the easiest answer and here is the example what we already use. 

But what is the solution for _compute_move_raw_ids and transfering details there 


Here is the example currently:

from odoo import fields, models, api

import logging

_logger = logging.getLogger(__name__)


class StockMove(models.Model): _inherit = "stock.move"
​width = fields.Float(string="Width", default=False,
​compute="_parse_from_bom_line", store=True) 

​height = fields.Float(string="Height", default=False,

​​compute="_parse_from_bom_line", store=True)


@api.depends("bom_line_id") def _parse_from_bom_line(self): for move in self: ​      ​move.width = move.bom_line_id.width if move.bom_line_id else False 

​move.height = move.bom_line_id.height if move.bom_line_id else False

Avatar
Descartar
Best Answer

Hi,

Try it using the _compute_move_raw_ids function:

from odoo import fields, models, api

class StockMove(models.Model):
    _inherit = "stock.move"

    width = fields.Float(string="Width", compute="_parse_from_bom_line", store=True)
    height = fields.Float(string="Height", compute="_parse_from_bom_line", store=True)

    @api.depends("raw_material_production_id.bom_id")
    def _parse_from_bom_line(self):
        for move in self:
            if move.raw_material_production_id.bom_id:
                bom_line = move.raw_material_production_id.bom_id.bom_line_ids.filtered(
                    lambda line: line.product_id.id == move.product_id.id
                )
                move.width = bom_line.width if bom_line else False
                move.height = bom_line.height if bom_line else False
            else:
                move.width = False
                move.height = False

Hope it helps

Avatar
Descartar
Best Answer

you can try this way:

from odoo import models, fields, api


class StockMove(models.Model):

    _inherit = 'stock.move'


    width = fields.Float(string='Width', compute='_compute_bom_line_data', store=True)

    height = fields.Float(string='Height', compute='_compute_bom_line_data', store=True)


    @api.depends('raw_material_production_id.bom_id', 'product_id')

    def _compute_bom_line_data(self):

        for move in self:

            if move.raw_material_production_id.bom_id:

                bom_line = move.raw_material_production_id.bom_id.bom_line_ids.filtered(

                    lambda line: line.product_id.id == move.product_id.id)

                move.width = bom_line.width

                move.height = bom_line.height


Avatar
Descartar
Autor

After fail and try this were the solution what I was looking for.

from odoo import models, fields, api, _, Command
import logging
_logger = logging.getLogger(__name__)
from odoo.exceptions import AccessError, UserError

class MrpProduction(models.Model):
_inherit = 'mrp.production'

def _get_move_raw_values(self, product_id, product_uom_qty, product_uom, operation_id=False, bom_line=False):
moves = super()._get_move_raw_values(product_id, product_uom_qty, product_uom, operation_id, bom_line)
moves['width'] = bom_line.width if bom_line else False
moves['height'] = bom_line.height if bom_line else False
return moves

Related Posts Respostes Vistes Activitat
0
de juny 21
3940
1
d’oct. 22
2576
0
d’oct. 22
1910
1
de jul. 25
392
4
d’abr. 25
7529