콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
3447 화면

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

아바타
취소
작성자 베스트 답변

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

아바타
취소
베스트 답변

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

아바타
취소
베스트 답변

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


아바타
취소
작성자

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

관련 게시물 답글 화면 활동
0
6월 21
4376
1
10월 22
2933
0
10월 22
2207
2
9월 25
353
1
7월 25
677