'Store the average price of the move on the move and product form (costing method \'real\')'

def _store_average_cost_price(self):

    for move in self.filtered((lambda move: (move.product_id.cost_method == 'real'))):
        if (any(((q.qty <= 0) for q in move.quant_ids)) or (move.product_qty == 0)):
            return
        valuation_price = sum(((q.qty * q.cost) for q in move.quant_ids))
        average_valuation_price = (valuation_price / move.product_qty)
        move.product_id.with_context(force_company=move.company_id.id).sudo().write({'standard_price': average_valuation_price})
        move.write({'price_unit': average_valuation_price})
    for move in self.filtered((lambda move: ((move.product_id.cost_method != 'real') and (not move.origin_returned_move_id)))):
        move.write({'price_unit': move.product_id.standard_price})
