Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
1386 Zobrazení

I have created the following column in the sale.order.line:


class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'


    x_studio_roles = fields.Float(

        string="Roles",

        store=True,

        readonly=False, 

        required=False

    )

I have created the same column in the stock.move:

class StockMove(models.Model):

    _inherit = "stock.move"


    x_studio_roles = fields.Float(

        string="Roles",      

        store=True,

        readonly=False, 

        required=False

    )

How can I now transfer the value from sale.order.line to stock.move?

Avatar
Zrušit
Nejlepší odpověď

If you just want to have the same value from Sale Order Line in Stock Move, you should slightly modify your field definition in your stock.move inherit.

The module sale_stock introduces a new field, sale_line_id.

So, given dependencies add up, you can simply go for

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

    x_studio_roles = fields.Float(related='sale_line_id.x_studio_roles', readonly=False)


This defines a direct relationship between those two fields, see also https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#reference-fields-related

Note that editing x_studio_roles on Stock Move now also changes the value in Sale Order Line.

If you don't want that, you can go for a "computed field" - which would allow you to set it only initially when the Stock Move is created and you then could check whether this field is set already and prevent further updates to it. What and how to apply this highly depends on what you would like to achieve at the end. For details about computed fields see https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#computed-fields

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
srp 25
1668
Stock update Vyřešeno
1
pro 24
1878
0
led 22
3433
1
bře 15
7302
0
bře 15
4299