Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
2239 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

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

Post Terkait Replies Tampilan Aktivitas
4
Mei 25
2501
2
Mei 25
5861
1
Mar 25
1686
4
Mar 25
4467
3
Feb 25
5471