Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
419 Widoki

I want to add a custom field in sale order line and want to show its value in purchase order line. It cannot get value from sale order line because when I apply debugger on 

def _prepare_procurement_values(self, group_id=False):
     res = super()._prepare_procurement_values(group_id) 

it will go only there then break but not execute  

def _prepare_purchase_order_line(self, product_id, product_qty, product_uom, company_id, values, po):
    res = super()._prepare_purchase_order_line(product_id, product_qty, product_uom, company_id, values, po)

that function.

What's the solution anyone suggest me?

Awatar
Odrzuć

Next time please use punctuation in your sentences and format your code so your question is actually readable.

Najlepsza odpowiedź

Hii,

please try this 
models/stock_rule.py

from odoo import models


class StockRule(models.Model):

    _inherit = 'stock.rule'


    def _prepare_purchase_order_line(

        self, product_id, product_qty, product_uom, company_id, values, po

    ):

        res = super()._prepare_purchase_order_line(

            product_id, product_qty, product_uom, company_id, values, po

        )

        # Pass custom field to PO line

        if values.get('x_custom_ref'):

            res['x_custom_ref'] = values['x_custom_ref']

        return res


i hope it is usefull

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,


You're trying to pass a custom field from the Sales Order Line to the corresponding Purchase Order Line, but during the procurement process, your custom value isn’t flowing through—even though you extended _prepare_procurement_values() and _prepare_purchase_order_line().


Try with the following.

1- Add field to sale.order.line

x_reference_code = fields.Char("Reference Code")


2-Extend _prepare_procurement_values() in sale.order.line

def _prepare_procurement_values(self, group_id=False):

    res = super()._prepare_procurement_values(group_id)

    res.update({

        'x_reference_code': self.x_reference_code,

    })

    return res


3- Extend _prepare_purchase_order_line() in purchase.order


def _prepare_purchase_order_line(self, product_id, product_qty, product_uom, company_id, values, po):

    res = super()._prepare_purchase_order_line(product_id, product_qty, product_uom, company_id, values, po)

   

    if 'x_reference_code' in values:

        res.update({

            'x_reference_code': values['x_reference_code'],

        })

    return res


Also, make sure purchase.order.line has this custom field.

x_reference_code = fields.Char("Reference Code")


Follow the three-step override above, and ensure the correct routes (Make To Order, Dropship, etc.) are active on your sale order line.


Hope it helps



Awatar
Odrzuć
Najlepsza odpowiedź

See for example https://github.com/odoo/odoo/blob/18.0/addons/sale/models/sale_order_line.py#L1445 and https://github.com/odoo/odoo/blob/18.0/addons/sale_project/models/sale_order_line.py#L474, i.e.

def _prepare_procurement_values(self, group_id=False):
    """ Prepare specific key for moves or other components that will be created from a stock rule
        coming from a sale order line. This method could be override in order to add other custom key that could
        be used in move/po creation.
        """
        return {}


_prepare_procurement_values() must have a return value (dict). Same goes for _prepare_purchase_order_line().

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
sie 25
1480
1
lip 25
568
1
lut 25
1394
2
cze 23
3214
1
sie 19
3133