from odoo import api, fields, models


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

    purchase_price = fields.Float(
        string='Cost', compute="_compute_purchase_price", digits='Product Price', store=True, readonly=False)

    # =========================== Compute functions =========================== #
    @api.depends('product_id', 'company_id', 'product_uom')
    def _compute_purchase_price(self):
        """
        note:: function to compute stock move purchase_price depending on
        fields [product_id, company_id, product_uom]
        """
        for line in self:
            if not line.product_id:
                line.purchase_price = 0.0
                continue
            line = line.with_company(line.company_id)

            # Convert the cost to the line UoM
            product_cost = line.product_id.uom_id._compute_price(
                line.product_id.standard_price,
                line.product_uom,
            )

            line.purchase_price = product_cost
