Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
2234 Vues

i want to add custom fields in approval.product.line 

1) on_hand quantity of selected product - on_hand_qty

2) last price  purchased (unit_cost) of selected product  - last_price_purchased

i am trying to add related fields through Technical, i don't know how to have relation in related field because when i am adding

Related Field = product_id.quantity 

it says "  Unknown field name 'quantity' in related field 'product_id.quantity'  " 

'quantity' field is in model 'stock_quant'

'unit_cost' field is in model 'stock_valuation_layer'   (unit_cost from LAST record of the selected product)

how i can add both related fields?  or any other way to achieve it?

please help.

regards

Avatar
Ignorer
Meilleure réponse

Hello SmithJohn45


In Odoo, the 'stock_quant' is not a field of the 'product.product' model, which is why you’re seeing the error message "Unknown field name ‘stock_quant’ in related field ‘product_id.stock_quant’". The 'stock_quant' model is used to manage the quantities of products in specific locations.


To add the 'on_hand_qty' and 'last_price_purchased' fields to the 'approval.product.line' model, you can create computed fields that calculate these values based on the 'product_id' field.

Here’s an example of how you might do this:


from odoo import api, fields, models


class ApprovalProductLine(models.Model):

    _inherit = 'approval.product.line'


    on_hand_qty = fields.Float(compute='_compute_on_hand_qty')

    last_price_purchased = fields.Float(compute='_compute_last_price_purchased')


    @api.depends('product_id')

    def _compute_on_hand_qty(self):

        for record in self:

            record.on_hand_qty = record.product_id.qty_available  # replace with your logic


    @api.depends('product_id')

    def _compute_last_price_purchased(self):

        for record in self:

            # replace with your logic to get the last purchase price

            record.last_price_purchased = record.product_id.standard_price


In this example, the 'on_hand_qty' field is computed based on the 'qty_available' field of the 'product_id', and the 'last_price_purchased' field is computed based on the 'standard_price' field of the 'product_id'. You should replace 'qty_available' and 'standard_price' with your own logic to calculate the on-hand quantity and the last purchase price.


Remember to replace the placeholders in the code with your actual data.


Best regards,
Maciej Burzymowski


Avatar
Ignorer
Auteur

thank you for reply.
first, i have updated my Opening Post and corrected already.
secondly, as mentioned, i don't know how to add the logic to get those values that's why i have requested here for help.
please help to add both fields.
regards

Publications associées Réponses Vues Activité
4
mai 25
2496
2
mai 25
5855
1
mars 25
1684
4
mars 25
4462
3
févr. 25
5465