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