Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
2973 Visualizzazioni

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
Abbandona
Autore Risposta migliore

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
Abbandona
Risposta migliore

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
Abbandona
Risposta migliore

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
Abbandona
Autore

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

Post correlati Risposte Visualizzazioni Attività
0
giu 21
4107
1
ott 22
2736
0
ott 22
2036
1
lug 25
510
4
apr 25
8184