Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
2609 Vistas

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 Mejor respuesta

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
Mejor respuesta

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
Mejor respuesta

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

Publicaciones relacionadas Respuestas Vistas Actividad
0
jun 21
3907
1
oct 22
2549
0
oct 22
1867
1
jul 25
383
4
abr 25
7490